结构体与文件求助!!
程序代码:
struct teacher { int num; char *name; char sex; float wage; struct teacher *next; }; void input() { struct teacher tea1; char n[20],ch; FILE *f; f=fopen("e:\\1.txt","wb"); if(f==NULL) printf("can not open file"); do { printf("enter number:");gets(n);tea1.num=atoi(n); printf("enter name:");gets(tea1.name); printf("enter sex:");tea1.sex=getchar();getchar(); printf("enter wage");gets(n);tea1.wage=atof(n); fwrite(&tea1,sizeof(struct teacher),1,f); printf("have another teacher record(y/n)?"); ch=getchar();getchar(); }while(ch=='Y'||ch=='y'); fclose(f); }我用结构体辅助编了个输入数据的函数 ,可是在输入第一个数据时windows就报错 弹出检查错误的窗口。但是上面的红色语句去掉后就没事了,这是怎么回事啊?