您的位置:首页 > 移动开发 > 微信开发

统计字数的小程序(1)

2013-08-19 21:10 246 查看
读取输入的的字符并报告其中的字符单词以及行数。

c primer plus 7.7

#include<stdio.h>
#include<stdbool.h>
#include<ctype.h>
#define STOP ']'
int main(void)
{    char c;
int n_character=0;
int n_word= 0;
int n_line = 0;
int p_line = 0;
bool inword = false;
char prev ;
printf("Please enter the strings to be analysis:\n");
prev= '\n';

while((c=getchar())!=STOP)
{    n_character++;
if(!inword && !isspace(c))
{    inword = true;
n_word++;
}
if(inword && isspace(c)) inword = false;
if(c == '\n') n_line++;
prev = c;
}

if(prev !='\n' ) p_line = 1;

printf(" charaters : %d\n words: %d\n lines: %d\n partical lines: %d\n",
n_character,n_word,n_line,p_line);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: