关于用fscanf文件读写的问题
Name Phone Num Address li 8888888 uu
zhang 888888 uu
zhao 88888 uuuu
如何用fscanf函数读出上面文件中的内容并显示编写一个程序但是不能正常显示程序如下谢谢了!
void output()
{
struct person one;
if((fp=fopen(filename,"rb"))==NULL)
{
printf("cant open!");
exit();
}
printf("\n\n%20s\n","sheet");
while(!feof(fp))
{
fscanf(fp,"%s%s%s",one.name,one.tel,one.addr);
printf("%-10s%-20s%-50s\n",one.name,one.tel,one.addr);
}
fclose(fp);
}
生成文件的函数如下:
void creat()
{
struct person one;
long s1;
printf("\nInput sheet name: ");
scanf("%s",filename);
if((fp=fopen(filename,"w"))==NULL)
{
printf("\n Cant creat");
exit();
}
fprintf(fp,"%-10s%-20s%-50s\n","Name","Phone Num","Address");
printf("\nInput Name,Phone Num and Address(End with 0)\n");
scanf("%s",one.name);
while(strcmp(one.name,"0"))
{
scanf("%s%s",one.tel,one.addr);
fprintf(fp,"%-10s%-20s%-50s\n",one.name,one.tel,one.addr);
scanf("%s",one.name);
}
fclose(fp);
}