a problem about Write record to a file using structure
//Write record to a file using structure#include <stdio.h>
#include <conio.h>
void main()
{
FILE *fp;
char another='Y';
struct emp
{
char name[40];
int age;
float bs;
};
struct emp e;
fp=fopen("employee.dat","w");
if(fp==NULL)
{
puts("can not open file");
exit(1);
}
while(another=='Y')
{
printf("\nEnter name,age,salary:");
scanf("%s,%d,%f",e.name,e.age,e.bs);
/*为什么运行时只接受到第一个字符串后面的都没接受到,比如输入mike 33 4000加回车,但每次都是只把第一个mike写进去了,后面的age和salary都没写进去,age一直是-1,salary是一大串数字*/
fprintf(fp,"%s %d %f",e.name,e.age,e.bs);
printf("%s %d %f\n",e.name,e.age,e.bs);
printf("Add another record(Y/N)");
fflush(stdin);
another=getche();
}
fclose(fp);
}
问题在程序注释里,向各位大神们请教了