修改一下程序,谢谢。
#include "stdio.h"main()
{
FILE *fp;
int ch;
int count=0;
if((fp=fopen("file1.text","w"))==NULL)
exit(0);
while((ch=fgetc(fp))!=EOF)
{
count+=ch;
}
fputs(count,fp);
fclose(fp);
}
#include "stdio.h" #include <stdlib.h> main() { FILE *fp; int ch; int count=0; if((fp=fopen("file1.text","w"))==NULL) exit(0); while((ch=fgetc(fp))!=EOF) { count+=(int)ch;//这是计算字符的ANS码的和 } //fputs(,fp);//你是不是想把读出来的字符再写进去???如果是先用个字符数组保存一下 printf("%d",count);//输出总和 fclose(fp); }
#include "stdio.h" #include <stdlib.h> main() { FILE *fp; char ch=0; char *p="sdfasdf"; int count=0; if((fp=fopen("file1.txt","r"))==NULL) exit(0); while((ch=getc(fp))!=EOF) { putchar(ch);//输出读入的东西 count+=(int)ch;//这是计算字符的ANS码的和 } //fputs(,fp);//你是不是想把读出来的字符再写进去???如果是先用个字符数组保存一下 printf("%d",count);//输出总和 fclose(fp); }好了 再去试试