📅  最后修改于: 2020-09-25 08:23:00             🧑  作者: Mango
int fscanf( FILE* stream, const char* format, ... );
fscanf()
函数读取数据,从文件流中读取数据,并将值存储到各个变量中。
它在
#include
int main ()
{
FILE *fp;
char name[50];
int age;
fp = fopen("example.txt","w");
fprintf(fp, "%s %d", "Tim", 31);
fclose(fp);
fp = fopen("example.txt","r");
fscanf(fp, "%s %d", name, &age);
fclose(fp);
printf("Hello %s, You are %d years old\n", name, age);
return 0;
}
运行该程序时,可能的输出为:
Hello Tim, You are 31 years old