15-4从键盘上输入字符串送到文件fiel1.txt中,然后再从该文件中读出所有的字符串。采用fprintf
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define nu NULL
int main()
{
FILE *fp;
char string[81];
if((fp=fopen("file1.txt","w"))==nu)
{
printf("cannot open this file");
exit(0);
}
while(strlen(gets(string))!=nu)
{
fputs(string,fp);
fprintf(fp,"\n");
}
fclose(fp);
if((fp=fopen("file1.txt","r"))==nu)
{
printf("cannot open this file");
exit(0);
}
else {
while(fgets(string,18,fp)!=nu)
{
printf("%s",string);
}
fclose(fp);
}
}