跪求~~~一道C语言编程题的答案~~~要程序代码~~
发布网友
发布时间:2022-04-30 18:04
我来回答
共2个回答
热心网友
时间:2022-06-28 19:49
#include "stdio.h"
struct student
{ char name[20];
char address[50];
char city[20];
char state[10];
}stu[4];
void input()
{ int i; FILE *fp;
if((fp=fopen("a.txt","r"))==NULL)
{ printf("cannot open file.\n");
exit(0); }
for(i=0;i<4;i++)
fscanf(fp,"%s %s %s %s",stu[i].name,stu[i].address,stu[i].city,stu[i].state);
fclose(fp);
}
void output()
{ int i;
printf(" name:");
for(i=0;i<4;i++)
printf(" %s\t ",stu[i].name);
printf("\naddress:");
for(i=0;i<4;i++)
printf(" %s",stu[i].address);
printf("\ncity,state:");
for(i=0;i<4;i++)
printf(" %s,%s\t",stu[i].city,stu[i].state);
}
void main()
{ input();
output();
}
结果是这样么:
name: H.Baker D.Rosso K.Tims B.Williams
address: 614FreemanSt. 83ChambersSt. 819RidgewoodRd. 24TremontAve.
city,state: Orange,NJ Madison,NJ Millburn,NJ Brooklyn,NY
有问题hi我
热心网友
时间:2022-06-28 19:49
a文件是你先处理好的还是用程序写?
程序输出的时候,具体格式是什么样的,请说清楚
是
Name:H.Baker,B.Williams...
还是
Name:B.Williams
Name:H.Baker
...