/*
* The program is to count the numbers of space, tab and enter
*
* zj
* 2010-5-6
*/
#include <stdio.h>
int main(){
int num_space = 0;
int num_tab = 0;
int num_enter = 0;
int c;
while((c=getchar()) != EOF){
if(c == ' ')
++num_space;
else if(c == '\t')
++num_tab;
else if(c == '\n')
++num_enter;
}
printf("The number of space is %d\n", num_space);
printf("The number of tab is %d\n", num_tab);
printf("The number of enter is %d\n", num_enter);
return 0;
}
|
写了这么多程序,居然犯下一个特别2的错误,开始编译的时候死活报错:
main.c:10: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
最后发现是把“int main()”写成了“int main”
实在是太2了。。。。。
PS:linux下的“EOF”的输入是“ctrl+D”