| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 11934 人关注过本帖
标题:统计一个文本文件中的单词个数和汉字个数
只看楼主 加入收藏
netaa001
Rank: 2
等 级:论坛游民
帖 子:73
专家分:69
注 册:2013-8-5
收藏
得分:0 
寻找志同道合的一起学习C语言,愿意的进群:330809827。
2013-08-05 21:30
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
对于单词  如何定义呢

比如  单独一个字母 算不算单词呢
比如  winxp+vc6.0  这算几个单词呢 1 2

DO IT YOURSELF !
2013-08-06 08:41
Dream_weaver
Rank: 1
等 级:新手上路
帖 子:37
专家分:2
注 册:2012-6-8
收藏
得分:0 
回复 12楼 wp231957
while(!feof(fp))
    {
        ch = fgetc(fp);
        if((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9'))
            flag = 0;
        else if(flag == 0 && (ch != '-' && ch != '/'&& ch != '\''))
        {
            num++;
            flag = 1;
        }
    }
统计单词个数,我的算法里判定条件是 :
若第一个字符为字母或者数字,第二个不为字符为字母或者数字(但可以为- / \这几个符号),单词个数就加一
也就是说:win-xp   cet4/6  a  都分别可以认为是一个单词,当然这种算法的健壮性明显不够,就比如你的含+的字符串
会被认为是2个单词。

我看过网上其它的程序,均以空格作为判别条件,太简陋了。
2013-08-06 14:21
Dream_weaver
Rank: 1
等 级:新手上路
帖 子:37
专家分:2
注 册:2012-6-8
收藏
得分:0 
我的帖子还没解决,为什么让我结贴?
2013-08-07 13:39
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
想要怎样才算解决?你的数据文件呢?

授人以渔,不授人以鱼。
2013-08-09 11:13
Dream_weaver
Rank: 1
等 级:新手上路
帖 子:37
专家分:2
注 册:2012-6-8
收藏
得分:0 
回复 15楼 TonyDeng
就是对一段含中英文的文本的统计,能够将我的程序更改正确,或者给出其它的程序也可以。
以下是测试文本。
我不知道错在哪里。
麻烦了。

Good morning, ladies and gentlemen!
It is really my honor to have this opportunity for an interview. I hope I can make a good performance today.  
Now I will introduce myself briefly. I am 26 years old, born in HuBei province. I got my bachelor degree from The three gorges University.   when I was a undergratuate student , I was the minister of my department in student union. During that time ,I have Applied for a  for utility model patent successfully. It now appears that the patent without any technology. But it can show my ability to find problem in our life, and then  solve it or improve it in some way.  Besides,   I spent most of my time on study, and I’ve passed CET-4/6 .I also passed examination in spoken English ,grade B. So i was given/awarded the national scholarship.

这算是有感而发。是和上一位网友沟通的结果。这位网友说他大三了,准备暑期要找份实习的工作,把简历发过来让我瞅瞅,看有问题没有。结果一看,还真有问题,我给他讲了一些写简历的基本思想,他觉得还能接受,沟通挺愉快的。
后来,我想想,干脆,在征得他同意后,把这个沟通结果发出来,让大家也参考一下,也许能帮得到大家也说不定哈。
嗯,还是那句话,一家之言,欢迎拍砖哈。
2013-08-09 12:34
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
这是纯英文文本啊,中文在哪?

授人以渔,不授人以鱼。
2013-08-09 12:42
Dream_weaver
Rank: 1
等 级:新手上路
帖 子:37
专家分:2
注 册:2012-6-8
收藏
得分:0 
回复 17楼 TonyDeng
Good morning, ladies and gentlemen!
It is really my honor to have this opportunity for an interview. I hope I can make a good performance today.  
Now I will introduce myself briefly. I am 26 years old, born in HuBei province. I got my bachelor degree from The three gorges University.   when I was a undergratuate student , I was the minister of my department in student union. During that time ,I have Applied for a  for utility model patent successfully. It now appears that the patent without any technology. But it can show my ability to find problem in our life, and then  solve it or improve it in some way.  Besides,   I spent most of my time on study, and I’ve passed CET-4/6 .I also passed examination in spoken English ,grade B. So i was given/awarded the national scholarship.

这算是有感而发。是和上一位网友沟通的结果。这位网友说他大三了,准备暑期要找份实习的工作,把简历发过来让我瞅瞅,看有问题没有。结果一看,还真有问题,我给他讲了一些写简历的基本思想,他觉得还能接受,沟通挺愉快的。
后来,我想想,干脆,在征得他同意后,把这个沟通结果发出来,让大家也参考一下,也许能帮得到大家也说不定哈。
嗯,还是那句话,一家之言,欢迎拍砖哈
2013-08-09 14:13
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册

授人以渔,不授人以鱼。
2013-08-09 18:17
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:27 
注意你的文本中上面英文处有个汉字,I',后面的是汉字字符。
这个文本是用ANSI编码储存的,即GB2312码,才可以用你上面的判别法。

[ 本帖最后由 TonyDeng 于 2013-8-9 18:23 编辑 ]

授人以渔,不授人以鱼。
2013-08-09 18:22
快速回复:统计一个文本文件中的单词个数和汉字个数
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012540 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved