Created
March 5, 2014 10:31
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define IN 1 /*光标在单词中时状态为1*/ | |
#define OUT 0 /*光标在单词外,即完成一个单词*/ | |
main() | |
{ | |
int c, nl, nw, nc, state; | |
printf("对输入的行、单词、字符进行计数\n"); | |
state = OUT; | |
nl = nw = nc = 0; | |
while ((c = getchar()) != EOF){ | |
++nc; | |
if (c == '\n'){ | |
++nl; | |
printf("nl+1\n"); /*检验循环是否运行*/ | |
} | |
if (c == ' ' || c == '\n' || c == '\t'){ | |
state = OUT; | |
printf("test\n"); /*检验循环是否运行*/ | |
} | |
else if (state == OUT){ | |
state = IN; | |
++nw; | |
printf("nw+1\n"); /*检验循环是否运行*/ | |
} | |
} | |
printf("以上输入包含:\n行数:"); | |
printf("%8d\n", nl); | |
printf("单词数:"); | |
printf("%6d\n", nw); | |
printf("字符数:"); | |
printf("%6d\n", nc); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment