简单的fscanf函数问题
#include<stdio.h>#include"ctype.h"
#define N 1000
main()
{
FILE *fp;
char str[N],str1[N],found=0;
while(1)
{
if((fp=fopen("TeleBook.txt","r"))==NULL)
{
printf("can,t open TeleBook or do,t have it");
getch();
exit(1);
}
printf("please input the name you want to search:");
scanf("%s",str);
while(!feof(fp))
{
fscanf(fp,"%s",str1);
if(strcmp(str1,str)==0)
{
found=1;
fscanf(fp,"%s",str1);
fscanf(fp,"%s",str1);
if(isdigit(str1[0]))
printf("%s tellphone number is %s\n",str,str1);
else
printf("%s tellphone is wrong\n");
break;
}
}
if(!found) printf("there don't have %s.\n",str);
fclose(fp);
}
getch();
}
TeleBook.txt文件:
aaa 111
bbb 222
ccc 333
运行编译后
aaa
aaa tellphone is wrong
bbb
bbb tellphone is wrong
ccc
ccc tellphone number is 333
为什么输入 aaa 不是输出 aaa tellphone number is 111请高手帮忙解答一下,在这里先谢了!