摘要:#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...
阅读全文
摘要:该书英文配套答案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, '
阅读全文
摘要:简单未考虑标点符号#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]...
阅读全文
摘要:#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{ ...
阅读全文
摘要:#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]
阅读全文
摘要: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...
阅读全文