//_59_fprintf()和fscanf()
//_59_main.cpp
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
int main()
{
FILE *fp;
char str[80],str1[80];
int i,j;
if((fp=fopen("text.txt","w"))==NULL)//以写入的方式打开
{
printf("Can not open the file.\n");
exit(0);
}
printf("Please enter a string and a number:\n");
fscanf(stdin,"%s %d",str,&i);//参数stdin表示从键盘读入
fprintf(fp,"%s %d",str,i);
fclose(fp);
if((fp=fopen("text.txt","r"))==NULL)//以读的方式打开
{
printf("Can not open the file.\n");
exit(0);
}
fscanf(fp,"%s %d",str1,&j);
fprintf(stdout,"%s %d\n",str1,j);//参数strout表示写向屏幕
fclose(fp);
system("pause");
return 0;
}
59_fprintf()和fscanf()
最新推荐文章于 2024-04-15 07:37:43 发布