您的位置:首页 > 编程语言 > C语言/C++

C语言实现计算一个文件中的单词个数

2018-01-16 13:50 288 查看
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);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐