Im doing a struct to register students´ info, previously I asked the user how many he wanted to register and proceeded to do it with a for loop:
case 1:
printf("How many students you want to register?:(no more than 10) \n");
scanf("%d", &num);
fflush(stdin);
printf("\n");
for(int i=0;i<num;i++){
alumno[i]=llenarInfo(alumno[i]);
}
printf("---------------------\n");
but how can I do it 1 at a time? I tried increasing i
after the loop for but if I register 2 or more and want to print them all it only prints the last one and when asking for the name of the student (atm of filling the info) it automatically jumps to the next member of the struct:
struct Usuario llenarInfo(struct Usuario alumno){
printf("Dame el nombre: ");
gets(alumno.nombre);
fflush(stdin);
printf("");
jumps this^^
printf("Dame el codigo de alumno: ");
scanf("%d", alumno.codigo);
fflush(stdin);
printf("");
printf("Dame el email: ");
scanf("%s", alumno.email);
fflush(stdin);
printf("");
printf("Que carrera estudia?: ");
scanf("%s", alumno.carrera);
fflush(stdin);
printf("");
printf("Cual es el sexo? H Hombre- M Mujer: ");
scanf("%s", alumno.sexo);
fflush(stdin);
printf("");
printf("Cual es la edad?: ");
scanf("%s", alumno.edad);
fflush(stdin);
printf("\n");
return alumno;