各位大神能否说下C语言如何在程序开始时候将文件内容读取到链表中呢
#include #include typedef struct student { int id; char name[32]; struct student* next;}ST;ST* create(ST* h) //头插创建链表;{ ST* head = h; ST* p =(ST*)malloc(sizeof(ST)); printf("请输入学号、姓名\n"); scanf("%d %s",&p->id,p->name); if(head = NULL) { head = p; p->next = NULL; } else { p->next = h; head = p; } return head;}void write(ST* h){ ST* p= h; FILE* fp=NULL; fp = fopen("1.txt","w"); if(fp!=NULL) { printf("打开成功\n"); } for(;p!=NULL;p=p->next) { fprintf(fp,"%d %s\n",p->id,p->name); } fclose(fp);}void print(ST* h){ ST* p = h; printf("学号\t 姓名\t\n"); while(p!=NULL) { printf("%d\t %s\t\n",p->id,p->name); p = p->next; }}int main(){ ST* head = NULL;// head=read(head); int n = 0; printf("请输入要创建学生信息的个数\n"); scanf("%d",&n); for(int i = 0;i |
免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。
版权声明:作者保留权利,不代表天盟立场。
|
|
|
|