#include #include typedef long long count_t; typedef enum {false,true} bool; count_t c_word(char *filename, count_t *,count_t *); int main(int argc,char *argv[]) { count_t file_lines,file_char,file_words,total_char,total_lines,total_words; unsigned int i; if(argc<2) { fprintf(stderr,"Usage: mywc FILE [FILE...]\n"); exit(1); } total_char=total_lines=total_words=0; for(i=1;i2) printf("%lld %lld %lld totale\n",total_lines,total_words,total_char); return 0; } count_t c_word(char *filename,count_t *n_lines, count_t *n_words) { int c; count_t n_char; bool in_word; FILE *fp=fopen(filename,"r"); if(fp==NULL) { fprintf(stderr,"mywc %s: ",filename); perror(""); return -1; } n_char=0; *n_lines=*n_words=0; in_word=false; while( (c=fgetc(fp))!=EOF) { n_char++; if(c=='\n') (*n_lines)++; if (c == ' ' || c == '\n' || c == '\t') in_word=false; else if(!in_word) { in_word=true; (*n_words)++; } } return n_char; }