progam iN C的字数

时间:2019-05-29 20:19:19

标签: c

我试图理解这段代码,首先我不明白这个OUT是什么意思,有人可以请我解释一下整个代码吗?

#define IN 1 /* inside a word */
#define OUT 0 /* outside a word */

/* count lines, words, and characters in input */

 main()
 {
   int c, nl, nw, nc, state;

   state = OUT;
   nl = nw = nc = 0;
   while((c = getchar()) != EOF) {
     ++nc;
     if (c == '\n')
       ++nl;
     if ( c == ' ' || c == '\n' || c == '\t')
       state = OUT;
     else if (state == OUT) {
       state = IN;
       ++nw;
     }
   }
   printf("%d %d %d\n",nl, nw, nc);
}

0 个答案:

没有答案