输入字符并统计个数,为什么字符个数总是多一倍?
#include<stdio.h>/**/#include<stdlib.h>
int main()
{
char a,name[10];
FILE *fp;
int num=0;
printf("please input filename:\n");
gets(name);
if((fp=fopen(name,"w"))==NULL)
{
printf("file open error!\n");
exit(0);
}
printf("please input char:\n");
a=getchar();
while(a!='#')
{
fputc(a,fp);
num++; //记录字符的个数
a=getchar();
}
fprintf(fp,"%d",num);
fclose(fp);
return 0;
}