首页 > 代码库 > <C Primer Plus>11 A Word-Count Program
<C Primer Plus>11 A Word-Count Program
#include <stdio.h>
#include "ctype.h"
#define STOP ‘|‘
int main(void){
char c;//Initializing
long n_char = 0L;
int n_word = 0;
int n_line = 0;
int inword = 0;//This is a flag making sure in word or not .
while ((c = getchar()) != STOP){//
n_char++;
if (c == ‘\n‘){
n_line++;
}
if (!isspace(c) && !inword){//c = getchar(), isn‘t space and not in word.
inword = 1;
n_word++;
}
if (isspace(c) && inword){// c is space and in word.
inword = 0;
}
}
printf("characters = %ld, word = %d, line = %d", n_char, n_word, n_line);
return 0;
}
<C Primer Plus>11 A Word-Count Program
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。