一个统计单词的程序
来源:互联网 发布:淘宝权限管理 编辑:程序博客网 时间:2024/06/05 06:43
#include<stdio.h>
#include<ctype.h>
#include<stdbool.h>
#define STOP '|'
int main()
{
char c;
char prev;
long n_chars = 0L;
int n_lines = 0;
int n_words = 0;
int p_lines = 0;
bool inword =false;
printf("Enter text to be analyzed(| to terminate):\n");
prev = '\n';
while((c =getchar() !=STOP))
{
n_chars++;
if(c == '\n')
n_lines++;
if(!isspace(c)&&!inword)
{
inword = true;
n_words++;
}
if(isspace(c) && inword)
{
inword = false;
prev =c;
}
}
if(prev !='\n')
p_lines = 1;
printf("characters = %ld,word %d, lines =%d, ",
n_chars, n_words, n_lines);
printf("partial lines =%d\n",p_lines);
return 0;
#include<ctype.h>
#include<stdbool.h>
#define STOP '|'
int main()
{
char c;
char prev;
long n_chars = 0L;
int n_lines = 0;
int n_words = 0;
int p_lines = 0;
bool inword =false;
printf("Enter text to be analyzed(| to terminate):\n");
prev = '\n';
while((c =getchar() !=STOP))
{
n_chars++;
if(c == '\n')
n_lines++;
if(!isspace(c)&&!inword)
{
inword = true;
n_words++;
}
if(isspace(c) && inword)
{
inword = false;
prev =c;
}
}
if(prev !='\n')
p_lines = 1;
printf("characters = %ld,word %d, lines =%d, ",
n_chars, n_words, n_lines);
printf("partial lines =%d\n",p_lines);
return 0;
}
这个程序高明之处在于,在读到每个单词开头时把inword设为1,在读到每个单词结尾时把inword设为0.只有在标记从0设置为1时,递增单词计数。
0 0
- 一个统计单词的程序
- 统计一个文件的单词的个数
- hadoop的统计单词程序WordCount
- 统计单词个数的简单程序
- 意外收获-ruby编写的一个简单统计单词出现次数的程序
- 统计一个句子单词的个数
- 统计一个英文文本的单词词频
- 【一个句子里,单词的个数统计】
- 单词,标点统计程序
- 单词出现统计程序
- 单词统计程序
- 小型单词统计程序
- 每天一个python小程序 004:任一个英文的纯文本文件,统计其中的单词出现的个数
- 练习2-4:编一个程序统计文件中特定单词出现的次数(要求使用string类的运算符==来查找单词)
- 练习2-4:编一个程序统计文件中特定单词出现的次数(要求使用string类的运算符==来查找单词) .
- 统计一个大小为30kb~300kb的文本中各单词出现的频率,并输出前十个单词和进行程序性能分析
- 练习2-3:编一个程序用来打开文件并统计文件中以空格隔开的单词数目
- C++统计单词小程序
- 回溯法 解决 8皇后问题
- C语言笔记1
- c++第五次作业
- jQuery介绍篇
- Java实现把正整数分解为质因数的乘积
- 一个统计单词的程序
- <UE4>分析UObjectBase
- 直接选择排序
- C# WinForm开发系列之chart控件画折线图和柱形图并自定义鼠标移动到数据标记点显示提示信息
- 跟我学JavaScript--HTML DOM--节点,DOM对象方法,DOM对象属性
- linux 安装ntfs-3g
- Leetcode算法练习-easy篇-Roman to Integer
- 多表连接查询
- poj 2387(Dijkstra优先队列优化)