09 2013 档案
练习1-21:编写程序entab,将空格串替换为最少数量的制表符和空格。。。(C程序设计语言 第2版)
摘要:#include #define N 5main(){ int i, j, c, lastc; lastc = 'a'; i = j = 0; while ((c=getchar()) != EOF) { if (lastc == ' ' && c == ' ') i++; else if (c == ' ') { lastc = ' '; i = 1; } else { for (j=0; j... 阅读全文
posted @ 2013-09-22 17:54 Samuel Yang 阅读(615) 评论(0) 推荐(1)
练习1-16:修改打印最长文本行的程序的主程序main,使之可以打印任意长度的输入行的长度,并尽可能多地打印文本(C程序设计语言 第2版)
摘要:该书英文配套答案Answer to Exercise 1-16, page 30Revise the main routine of the longest-line program so it will correctly print the length of arbitrarily long input lines, and as much as possible of the text. /* This is the first program exercise where the spec isn't entirely * clear. The spec says, ' 阅读全文
posted @ 2013-09-18 18:51 Samuel Yang 阅读(1296) 评论(0) 推荐(0)
练习1-13:编写一个程序,打印输入中单词长度的直方图(水平)(C程序设计语言 第2版)
摘要:简单未考虑标点符号#include #define MAX_WORD_LEN 10#define BLANK 0#define IN_WORD 1#define START 2main(){ int c, word_len, last_ch, i, j, len_array[MAX_WORD_LEN+1]; for(i=0; i MAX_WORD_LEN){ len_array[MAX_WORD_LEN]++; }else{ len_array[i-1]... 阅读全文
posted @ 2013-09-18 17:17 Samuel Yang 阅读(428) 评论(0) 推荐(0)
练习1-12:编写一个程序,以每行一个单词的形式打印其输入(C程序设计语言 第2版)
摘要:#include #define NOT_BLANK 1#define BLANK 0main(){ int c; int last_ch = NOT_BLANK; while ((c=getchar()) != EOF){ if (c == ' ' || c == '\n' || c == '\t'){ if (last_ch == NOT_BLANK) putchar('\n'); last_ch = BLANK;//这条语句可以包括在最近的if里面 }else{ ... 阅读全文
posted @ 2013-09-17 10:48 Samuel Yang 阅读(315) 评论(0) 推荐(0)
练习2-3:十六进制数字字符串转换为等价整型值,字符串允许包含的数字包括:0~9、a~f、A~F、x、X(C程序设计语言 第2版)
摘要:#include #include #include int htoi(char s[]){ unsigned int len = strlen(s); unsigned int i = 0; int sum = 0; while(len){ --len; if ('a' <= s[len] && s[len] <= 'f'){ sum += (s[len] - 'a' + 10) * pow(16, i++); }else if ('A' <= s[len] && s[len] 阅读全文
posted @ 2013-09-16 12:25 Samuel Yang 阅读(297) 评论(0) 推荐(0)
练习1-23:删去C语言程序中所有的注释语句(C程序设计语言 第2版)
摘要:1 #include 2 main() 3 { 4 FILE * fp_i; 5 FILE * fp_o; 6 fp_i = fopen("input.txt", "r"); 7 fp_o = fopen("output.txt", "w"); 8 char ch; 9 int sign;10 while((ch=fgetc(fp_i)) != EOF){11 if (ch == '/' ){12 13 ch=fgetc(fp_i);14 if (ch == '/'){1... 阅读全文
posted @ 2013-09-16 10:46 Samuel Yang 阅读(269) 评论(0) 推荐(0)