fsanf()函数的用法问题!
#include<stdio.h>void main()
{
FILE *fp;
char a[12];
int b;
char c[10];
if((fp = fopen("f:\\1.txt","r"))==NULL)
{
printf("open fail !\n");
}
else
printf("open success !\n");
fgets(c,10,fp);
puts(c);
while(!(feof(fp)))
{
fscanf(fp,"%s\t%d",a,&b);
printf("%s\t%d\n",a,b);
}
}
TXT文件内容如下(学生和学号内容以TAB键跳开);
学生 学号
a 5
b 6
c 7
d 9
本人的最后输入结果最后一行重复了一次,如果把程序改成这样就可以:
#include<stdio.h>
void main()
{
FILE *fp;
char a[12];
int b;
char c[10];
if((fp = fopen("f:\\1.txt","r"))==NULL)
{
printf("open fail !\n");
}
else
printf("open success !\n");
fgets(c,10,fp);
puts(c);
fscanf(fp,"%s\t%d",a,&b);
while(!(feof(fp)))
{
printf("%s\t%d\n",a,b);
fscanf(fp,"%s\t%d",a,&b);
}
}
请高手帮忙解答,谢了!