#include<stdio.h>
#define OUT 0
#define IN 1
main()
{
int c, nw, state;
nw = 0;
state = OUT;
while ((c = getchar()) != EOF) {
if (c == ' ' || c == '/t' || c == '/n')
if (state == IN) /* 去掉这行,程序运行时正确的,但是没摸清楚原因,求教 。*/
state = OUT;
else if (state == OUT) {
state = IN;
++nw;
}
}
printf("nw:%d/n", nw);
system("pause");
}
错误运行结果如下:
#include<stdio.h>
#define OUT 0
#define IN 1
main()
{
int c, nw, state;
nw = 0;
state = OUT;
while ((c = getchar()) != EOF) {
if (c == ' ' || c == '/t' || c == '/n')
state = OUT;
else if (state == OUT) {
state = IN;
++nw;
}
}
printf("nw:%d/n", nw);
system("pause");
}
正确的运行结果: