#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; }
时间: 2024-11-10 10:12:19