编写一个统计字符数、单词数、行数的程序。
自己乱敲的版本:
#include <stdio.h>
int main (void)
{
int a = 0;
int b = 1;
int c = 1;
char n;
scanf("%c",&n);
while ( n != '#')
{
a++;
if (n == '\n')
c++;
else if (n == ' ')
b++;
scanf("%c",&n);
}
printf("%d %d %d",a,b,c);
return 0;
}
C primer plus的参考答案略,差别蛮大的。