c语言问题(不确定个数的结构组写入一个数组)?

我想把不确定个数的结构组写入一个数组,这个程序有什么问题? #include <stdlib.h> #include <stdio.h> struct student{ int term; int ID; char lastName[15]; char firstName[15]; char subject[3]; int catalog; char section[3]; }; int main(int argc, char* argv[]) { int size; char fileName; printf("Please enter the name of the input file: "); scanf("%s", &fileName); printf("Please enter the number of the students: "); scanf("%d",&size); struct student* class; FILE *ifp; int i; for (i=0;i<size;i++){ scanf("%d",class[i].term,); scanf("%d",class[i].ID); scanf("%s",class[i].lastName); scanf("%s",class[i].firstName); scanf("%s",class[i].subject); scanf("d%",class[i].catalog); scanf("%s\n",class[i].section); } class=malloc(sizeof(struct student)*size); ifp=fopen(fileName, "w"); if(ifp==NULL){ printf("The input file was not opened\n"); return 1; } fwrite(people,sizeof(struct student)*size,1,ifp); fclose(ifp); return 0; }

没有初始化指针 struct student* class; class=new student[size];

求采纳
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网