fscanf函数和scanf函数有什么区别?
来源:百度知道 编辑:UC知道 时间:2024/07/03 00:23:32
我知道fprintf 是写入文件数据的,那么 fscanf呢
函数原型
#include <stdio.h>
int scanf(const char *format,...);
int fscanf(FILE*stream,constchar*format,[argument...]);
读取数据来源
scanf 标准输入设备(控制台用户输入)读入数据;
fscanf从文件流(FILE*)读入数据。
前提条件
scanf在控制台应用程序启动后即可使用;
fscanf使用前需要调用 fopen打开文件,使用后需要用fclose关闭文件。例如从文件"d:\\note.txt"中读取一个字符串:
FILE * inputFile = fopen("d:\\note.txt", "r"); // 打开文件
char str[100];
fscanf ( inputFile, "%s", str); // 读取一个字符串
fclose ( inputFile ); &nb