turbo c2.0中fscanf()函数问题

来源:百度知道 编辑:UC知道 时间:2024/06/17 23:01:08
#include<stdio.h>
main()
{
char *s, m[20];
int i;
FILE *fp;
fp=fopen("G:\\test2.txt", "r"); /*打开文字文件只读*/
fscanf(fp, "%d", &i); /*读取整型数*/
printf("%d", i); /*输出所读整型数*/
system("pause");
}

这个程序运行是输出test.txt里的数字吗?是哪些数字,

如果test.txt里没有内容,那输出的数字是哪里来的。

这样的话,fscanf函数有返回值,如果文件为空,就不会向变量输入数值,变量保持原样。。

#include<stdio.h>

int main(void)
{
char *s, m[20];
int i=50;
FILE *fp;

fp=fopen("gao.txt", "r"); /*打开文字文件只读*/
fscanf(fp, "%d", &i); /*读取整型数*/
printf("%d", i); /*输出所读整型数*/
system("pause");

return 0;
}

把变量赋初值,就会知道。。
不懂可以查查MSDN