struct sushe *intput_shuji()
{
int jisuan(char a[]);
FILE *out;
char ch,outfile[256];
int n=0;
char line[1024];
struct sushe *head;
struct sushe *p,*q;
head=p=(struct sushe*)malloc(sizeof(struct sushe)); //申请一个空间,头指针head为空的
printf("输入读入文件的名字:");
scanf("%s",outfile);
if((out=fopen(outfile,"r"))==NULL)
{
printf("无法打开此文件\n");
exit(0);
}
while(!feof(out))
{
q=(struct sushe*)malloc(sizeof(struct sushe));
p->next=q;
p=q;
fgets(line,50,out);
sscanf(line,"%s %s %d %s %d %d %d",p->area,p->storey,&p->number,p->name,&p->electric,&p->water,&p->drink);
}
q->next=NULL;
fclose(out);
return head;//返回头指针
}
{
int jisuan(char a[]);
FILE *out;
char ch,outfile[256];
int n=0;
char line[1024];
struct sushe *head;
struct sushe *p,*q;
head=p=(struct sushe*)malloc(sizeof(struct sushe)); //申请一个空间,头指针head为空的
printf("输入读入文件的名字:");
scanf("%s",outfile);
if((out=fopen(outfile,"r"))==NULL)
{
printf("无法打开此文件\n");
exit(0);
}
while(!feof(out))
{
q=(struct sushe*)malloc(sizeof(struct sushe));
p->next=q;
p=q;
fgets(line,50,out);
sscanf(line,"%s %s %d %s %d %d %d",p->area,p->storey,&p->number,p->name,&p->electric,&p->water,&p->drink);
}
q->next=NULL;
fclose(out);
return head;//返回头指针
}
本文介绍了一个使用C语言实现的程序,该程序从文件中读取宿舍数据,并将其存储在一个链表结构中。每个节点代表一个宿舍,包含区域、楼层等信息。程序首先提示用户输入文件名,然后打开并逐行读取文件内容。
768

被折叠的 条评论
为什么被折叠?



