1、
#include <stdio.h> #include <ctype.h> #include <stdbool.h> #define STOP ‘|‘ int main(void) { char ch; char prep; long n_ch = 0L; int n_lines = 0; int n_words = 0; int n_p_line; bool inword = false; while((ch = getchar()) != STOP) { n_ch++; if(ch == ‘\n‘) n_lines++; if(!isspace(ch) && !inword) { inword = true; n_words++; } if(isspace(ch) && inword) inword = false; prep = ch; } if(prep != ‘\n‘) n_p_line = 1; printf("n_ch : %ld\n", n_ch); printf("n_lines : %d\n", n_lines); printf("n_words : %d\n", n_words); printf("n_p_line: %d\n", n_p_line); return 0; }