I am doing some C test programs to learn a little more about the language, the program I am doing now is to show the grades of some students:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
struct alumno{
char name[21];
int edad;
int promedio;
}alumnos[50];
int main(){
srand (time(NULL));
int cantidad, i, n;
char names[7][10] = {"Juan", "Max", "Julia", "Pablo", "Alejandra", "Regina", "Angel"};
char lstnames[5][10] = {"Perez", "Gonzales", "Martinez", "Rodriguez", "Contreras"};
printf("Ingrese la cantidad de alumnos: ");scanf("%i", &cantidad);
for(i=0;i<cantidad-1;i++){
alumnos[i].name = "%s %s",names[rand()%8], lstnames[rand()%6];
alumnos[i].edad = rand() % 12 + 19;
alumnos[i].promedio = rand() % 11;
printf("\n----------\nNombre: %s\nEdad: %i\nPromedio: %i\n",alumnos[i].name, alumnos[i].edad,alumnos[i].promedio);
}
return 0;
}
This is the error message that appears to me:
5.c: En la funci¾n 'main':
5.c:17:19: error: assignment to expression with array type
alumnos[i].name = "%s %s",names[rand()%8], lstnames[rand()%6];
^