/*-------------------------------------------------------
【程序填空】
---------------------------------------------------------
题目:下列给定程序的功能是:从键盘输入若干行字符串(每行不超过80个字符),写入文
件myfile4.txt中,用-1作字符串输入结束的标志,然后将文件的内容显示在屏幕
上。文件的读写分别由函数ReadText和WriteText实现。
-------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void WriteText(FILE *);
void ReadText(FILE *);
main()
{
FILE *fp;
if((fp=fopen("myfile4.txt","w"))==NULL)
{
printf(" open fail!!\n");
exit(0);
}
WriteText(fp);
fclose(fp);
if((fp=fopen("myfile4.txt","r"))==NULL)
{
printf(" open fail!!\n");
exit(0);
}
ReadText(fp);
fclose(fp);
}
/***********SPACE***********/
void WriteText(FILE *fw)
{
char str[81];
printf("\nEnter string with -1 to end :\n");
gets(str);
while(strcmp(str,"-1")!=0)
{
/***********SPACE***********/
fputs(str,fw);
fputs("\n",fw);
gets(str);
}
}
void ReadText(FILE *fr)
{
char str[81];
printf("\nRead file and output to screen :\n");
fgets(str,81,fr);
while( !feof(fr) )
{
/***********SPACE***********/
printf("%s",str);
fgets(str,81,fr);
}
}