#include "stdio.h"
int main(int argc,char *argv)
{
FILE *fp;
char ch;
if((fp=fopen("aaa.txt","wt+"))==NULL)
{
printf("Cannot open file!");
getch();
exit(1);
}
printf("input a string:\n");
ch=getchar();
while(ch!='\n')
{
fputc(ch,fp);
ch=getchar();
ch=fgetc(fp);
while(ch!=EOF)
{
putchar(ch);
ch=fgetc(fp);
}
printf("\n");
fclose(fp);
}
int main(int argc,char *argv)
{
FILE *fp;
char ch;
if((fp=fopen("aaa.txt","wt+"))==NULL)
{
printf("Cannot open file!");
getch();
exit(1);
}
printf("input a string:\n");
ch=getchar();
while(ch!='\n')
{
fputc(ch,fp);
ch=getchar();
}
//rewind的函数就是把文件指针从你现在读取的位置,重新回到文件开头
rewind(fp);ch=fgetc(fp);
while(ch!=EOF)
{
putchar(ch);
ch=fgetc(fp);
}
printf("\n");
fclose(fp);
}