#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp;
char ch;
if((fp = fopen("demo.txt","w")) == NULL )
{
printf("failure to open demo.txt!\n");
exit(0);
}
ch = getchar();
while(ch != '\n')
{
fputc(ch,fp);
ch = getchar();
}
fclose(fp);
return 0;
}
if((fp = fopen("demo.txt","w")) == NULL ) 中操作方式W ,通过运行程序可知下一次的键入值会将上一次的值覆盖
第一次运行
第二次运行