早上卖咖啡 早上卖咖啡
关注数: 24 粉丝数: 17 发帖数: 281 关注贴吧数: 136
萌新求助,程序没有报错但是运行也没有效果 想导入文本内容,然后在导出成另一个文本,但是运行之后控制台只是卡了一会,然后就是任意键退出,但是没有导出任何文件#include<stdio.h> #include<string.h> #include<stdlib.h> struct STUDENT //ѧÉú { char id[11];//ѧºÅ char name[21];//ÐÕÃû char sex[4];//ÐÔ±ð char className[31];//°à¼¶ STUDENT *next;//Ö¸ÏòÏÂÒ»¸öѧÉú½á¹¹ÌåµÄÖ¸Õë }; struct STUDENT *creat(struct STUDENT *); void main() { struct STUDENT *head; head=NULL; head=creat(head); struct STUDENT *temp; temp=head; FILE *fp; fp=fopen("students.txt","r"); fgets(temp->id,3,fp); fseek(fp,1,SEEK_CUR); fgets(temp->name,3,fp); fseek(fp,1,SEEK_CUR); fgets(temp->sex,1,fp); fseek(fp,1,SEEK_CUR); fgets(temp->className,4,fp); temp=temp->next; fgets(temp->id,3,fp); fseek(fp,1,SEEK_CUR); fgets(temp->name,3,fp); fseek(fp,1,SEEK_CUR); fgets(temp->sex,1,fp); fseek(fp,1,SEEK_CUR); fgets(temp->className,4,fp); temp=temp->next; fgets(temp->id,3,fp); fseek(fp,1,SEEK_CUR); fgets(temp->name,2,fp); fseek(fp,1,SEEK_CUR); fgets(temp->sex,1,fp); fseek(fp,1,SEEK_CUR); fgets(temp->className,4,fp); fclose(fp); struct STUDENT *tem; tem=head; FILE *daochu; daochu=fopen("students-out.txt","w"); fprintf(daochu,"ѧºÅ\tÐÕÃû\tÐÔ±ð\t°à¼¶\n"); fprintf(daochu,"%s\t%s\t%s\t%s\n",tem->id,tem->name,tem->sex,tem->className); tem=tem->next; fprintf(daochu,"%s\t%s\t%s\t%s\n",tem->id,tem->name,tem->sex,tem->className); tem=tem->next; fprintf(daochu,"%s\t%s\t%s\t%s\n",tem->id,tem->name,tem->sex,tem->className); fclose(daochu);}struct STUDENT *creat(struct STUDENT *head) { struct STUDENT *p1,*p2; p1=(struct STUDENT *)malloc(sizeof(struct STUDENT)); for(int i=0;i<3;i++) { if(head==NULL) { head=p1; } else { p2->next=p1; p2=p1; p1=(struct STUDENT *)malloc(sizeof(struct STUDENT)); } } p2->next=NULL; return head; }
求大佬帮忙,没有报错但是运行也没有效果 想导入文本内容,然后在导出成另一个文本,但是运行之后控制台只是卡了一会,然后没有效果#include<stdio.h> #include<string.h> #include<stdlib.h> struct STUDENT //ѧÉú { char id[11];//ѧºÅ char name[21];//ÐÕÃû char sex[4];//ÐÔ±ð char className[31];//°à¼¶ STUDENT *next;//Ö¸ÏòÏÂÒ»¸öѧÉú½á¹¹ÌåµÄÖ¸Õë }; struct STUDENT *creat(struct STUDENT *); void main() { struct STUDENT *head; head=NULL; head=creat(head); struct STUDENT *temp; temp=head; FILE *fp; fp=fopen("students.txt","r"); fgets(temp->id,3,fp); fseek(fp,1,SEEK_CUR); fgets(temp->name,3,fp); fseek(fp,1,SEEK_CUR); fgets(temp->sex,1,fp); fseek(fp,1,SEEK_CUR); fgets(temp->className,4,fp); temp=temp->next; fgets(temp->id,3,fp); fseek(fp,1,SEEK_CUR); fgets(temp->name,3,fp); fseek(fp,1,SEEK_CUR); fgets(temp->sex,1,fp); fseek(fp,1,SEEK_CUR); fgets(temp->className,4,fp); temp=temp->next; fgets(temp->id,3,fp); fseek(fp,1,SEEK_CUR); fgets(temp->name,2,fp); fseek(fp,1,SEEK_CUR); fgets(temp->sex,1,fp); fseek(fp,1,SEEK_CUR); fgets(temp->className,4,fp); fclose(fp); struct STUDENT *tem; tem=head; FILE *daochu; daochu=fopen("students-out.txt","w"); fprintf(daochu,"ѧºÅ\tÐÕÃû\tÐÔ±ð\t°à¼¶\n"); fprintf(daochu,"%s\t%s\t%s\t%s\n",tem->id,tem->name,tem->sex,tem->className); tem=tem->next; fprintf(daochu,"%s\t%s\t%s\t%s\n",tem->id,tem->name,tem->sex,tem->className); tem=tem->next; fprintf(daochu,"%s\t%s\t%s\t%s\n",tem->id,tem->name,tem->sex,tem->className); fclose(daochu);}struct STUDENT *creat(struct STUDENT *head) { struct STUDENT *p1,*p2; p1=(struct STUDENT *)malloc(sizeof(struct STUDENT)); for(int i=0;i<3;i++) { if(head==NULL) { head=p1; } else { p2->next=p1; p2=p1; p1=(struct STUDENT *)malloc(sizeof(struct STUDENT)); } } p2->next=NULL; return head; }
1 下一页