#include <stdio.h>
#include <string.h>
struct student{
char name[20];
char studentNumber[5];
int yearOfBirth;
float avgPoint;
};
int main(){
struct student hssv[3];
int i;
//input info for students, this case its 3 students
for(i=0; i<3; i++){
printf("Input element value: ");
printf("\nInput your name: ");
fflush(stdin);
fgets(hssv[i].name, sizeof(hssv[i].name), stdin); //this line doesnt work for the loop
printf("Input your student code: ");
fflush(stdin);
fgets(hssv[i].studentNumber, sizeof(hssv[i].studentNumber), stdin);
printf("Input your year of birth: ");
scanf("%d", &hssv[i].yearOfBirth);
printf("Input your point: ");
scanf("%f", &hssv[i].avgPoint);
}
//output info
for(i=0; i<3; i++){
printf("\nOutput element value: ");
printf("\nYour name: %s", hssv[i].name);
printf("\nInput your student code: %s", hssv[i].studentNumber);
printf("\nInput your year of birth: %d", hssv[i].yearOfBirth);
printf("\n\nInput your point: %f", hssv[i].avgPoint);
}
return 0;
}
我不知道为什么它不能正常工作,我使用了get(),但随后出现了一个警告,说我应该使用fget().然后我查了一下,并使用了它,但同样的结果一直在发生. FOR NAME的输入对循环中的第二个向前不起作用,我猜是缓冲区溢出?但是我已经在使用fflush()了.请帮帮我...