In my code, I request a series of data from the user using the gets()
function. The problem is that at a certain point in the program when requesting a data with gets()
it simply jumps to the next request and leaves the variable blank , I tried to clean the buffer in the following way and it does not work:
fflush(stdin);
This is the code:
#include <stdio.h>
#include <string.h>
struct alumnos{
char nombre[10];
char dni[20];
int edad;
};
int main(){
struct alumnos myalumno[3];
int i;
for(i=0;i<=2;i++){
printf("Ingrese el nombre del alumno %i: ",i+1);
fflush(stdin);
gets(myalumno[i].nombre);
printf("Ingrese el DNI del alumno %i: ",i+1);
fflush(stdin);
gets(myalumno[i].dni);
printf("Ingrese la edad del alumno %i: ",i+1);
fflush(stdin);
scanf("%i",&myalumno[i].edad);
}
}