#include <stdio.h>
#include <stdlib.h>
// 13.10-4.txt
int main()
{
int ch;
FILE *fp;
unsigned long count = 0;
char file_name[30];
char str[30];
printf("文件名:\n");
scanf("%s",file_name);
if ((fp = fopen(file_name, "a+")) == NULL)
{
printf("Can't open %s\n", file_name);
exit(EXIT_FAILURE);
}
printf("需要添加的信息(ctrl+z结束):");
while(scanf("%s",str) != EOF)
{
fprintf(fp, "%s", str);
}
fseek(fp, 0L, SEEK_SET);
while ((ch = getc(fp)) != EOF)
{
putc(ch,stdout);
count++;
}
fclose(fp);
printf("\nFile %s has %lu characters\n", file_name, count);
return 0;
}