一步一步向前走。。。
希望能多看,多写,多想,多得。。。
代码:
1 #include2 #include 3 4 #define IN 1 5 #define OUT 0 6 int main(int argc, char *argv[]) 7 { 8 int c, nl, nw, nc, state; 9 10 state = OUT;11 nl = nw = nc = 0;12 while ((c = getchar()) != EOF) {13 ++nc;14 if ( c == '\n')15 ++nl;16 if (c == ' ' || c == '\n' || c == '\t')17 state = OUT;18 else if (state == OUT){19 state = IN;20 ++nw;21 }22 }23 printf("new char number is : %d\n",nc);24 printf("new line number is : %d\n",nl);25 printf("new word number is : %d\n",nw);26 27 system("PAUSE"); 28 return 0;29 }
截图: