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语言实现计算一个文件中的单词个数
最新推荐文章于 2023-02-18 13:41:13 发布
本文介绍了一个简单的C语言程序,该程序用于统计指定文件中的字符数、单词数和行数。通过对文件逐个字符读取并根据特定条件计数,演示了基本的文件操作和字符串处理技巧。
1万+

被折叠的 条评论
为什么被折叠?



