#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
struct person
{
char num[3]; //编号
char name[20]; //姓名
char age[2]; //年龄
char sex[2]; //性别
char phone[12]; //电话
char adress[50]; //地址
char e_mail[20]; //电子邮件
char classify[10]; //分类名
}per[100]; //最大数为100
int load()/*加载函数*/
{
FILE *fp;
int i;
if((fp=fopen("person.txt","r"))==NULL)
{
printf("\nCannot open file\n");
return 0;
}
for(i=0;!feof(fp);i++)
{
fscanf(fp,"%s%s%s%s%s%s%s%s",&per[i].num,&per[i].name,&per[i].age,&per[i].sex,&per[i].phone,&per[i].adress,&per[i].e_mail,&per[i].classify);
}
fclose(fp);
return(i);
}
int main()
{
int n,i;
n=load();
for(i=0;i<n;i++)
{
printf("%s %-7s %-2s %-2s %-12s %-50s %-20s %-10s\n",per[i].num,per[i].name,per[i].age,per[i].sex,per[i].phone,per[i].adress,per[i].e_mail,per[i].classify);
}
}
goooool