void count_world()
{
int nl, nc, nw, state, c;
nl = nc = nw = 0;
FILE *fp;
state = OUT;
fp = fopen("./a.txt","r");
while((c = fgetc(fp)) != EOF)
{
DEBUG("c:%c\n",c);
nc++;
if(c == '\n')
nl++;
if ( (' ' == c ) || ('\t' == c ) || ('\n' == c ) )
{
DEBUG2("in the out the world");
state = OUT;
}
else if (OUT == state )
{
DEBUG2("in the world");
state = IN;
nw++;
}
}
DEBUG("nl=%d\nnc=%d\nnw=%d\n",nl,nc,nw);
}
C语言实现计算一个文件中的单词个数
最新推荐文章于 2022-08-01 19:25:21 发布