函数fun的功能是将形参给定的字符串、整数、浮点数写到文本文件中,再用字符方式从此文本文件中逐个读入并显示在屏幕上
#include <stdio.h>
void fun(char *s, int a, double f)
{
/**********found**********/
FILE* fp;//定义文本文件类型
char ch;
fp = fopen("file1.txt", "w");
fprintf(fp, "%s %d %f\n", s, a, f);
fclose(fp);
fp = fopen("file1.txt", "r");
printf("\nThe result :\n\n");
ch = fgetc(fp);
/**********found**********/
while (!feof(fp))//判断文件是否结束
{
/**********found**********/
putchar(ch);//显示读出的字符
ch = fgetc(fp);
}
putchar('\n');
fclose(fp);
}
main()
{ char a[10]="Hello!"; int b=12345;
double c= 98.76;
fun(a,b,c);
}
浙公网安备 33010602011771号