2011年7月10日
摘要: 源于《The C Programming Language》P14的一道例题: 统计输入中的行数,单词数,字符数(单词的定义:其中不包括空格,制表符,换行符的字符序列) #include <stdio.h> #define IN 1 #define OUT0 int main() { int c, nl, nw, nc, state; state = OUT; nl = nw = nc = 0; while((c = getchar()) != EOF) ++nc; if(c == '/n') ++nl; if(c == ' ' || c == &# 阅读全文
posted @ 2011-07-10 15:41 将军之盾 阅读(416) 评论(0) 推荐(0) 编辑
摘要: 源于《The C Programming Language》P17 pr1-13: 编写一个程序,打印输入中单词长度的直方图。 代码 main.c 1 /************************************************************** 2 直方图定义: 3 n:某个长度单词出现的次数(长度为4的单词出现了9次,则n = 9) 4 M:出现最频繁的长度的次数 5 H:定义的直方图的最大长度(本例中为MAXHIST) 6 **************************************************************/ 7 . 阅读全文
posted @ 2011-07-10 15:40 将军之盾 阅读(1146) 评论(0) 推荐(0) 编辑
摘要: 来源于《The C Programming Language》的一道习题(P13,PR1-9): 编写一个将输入复制到输出的程序,并将其中连续的多个空格用一个空格代替 自己实现: #include <stdio.h> int main() { int c, flag; flag = 0; while((c = getchar()) != EOF) if(c == ' ' && flag == 0) { putchar(c); ++flag; } else if(c == ' ' && flag != 0) ++flag 阅读全文
posted @ 2011-07-10 15:37 将军之盾 阅读(230) 评论(0) 推荐(0) 编辑