C语言编写,如何做到只提取文件数字。

一个文件名为1.txt文本里的内容
科目a 科目b
学生A 90 80
学生B 85 100
怎样用C语言操作,只读取数字90,80,85,100呢?
1楼说的我也想过,难道没有函数可以用么?

//看得明白的吧

#include <stdio.h>
#include <assert.h>

int main()
{
FILE *fp=fopen("c:\\1.txt","r");
assert(fp!=NULL);

char s[1000];

while(fscanf(fp,"%s",s)==1)
{
int n;
if(sscanf(s,"%d",&n)==1)
//printf("%d\n",n);
printf("数字:%d\n",n);
else
{
printf("跳过字符串:%s\n",s);
}
}

fclose(fp);

return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-09-30
可以用一个if语句来判断啊,不符合要求的就丢掉。