/* Count the number of lines, words, characters, */#include <stdio.h>int line (file *op); int word (file *op); int main (int argc, char const *argv[] {File *op = Null;int string = 0;if ((Op=fopen ("./statistics.c", "R")) ==null)//opens the file itself. {printf ("error!\n"); return-1;} while (!feof (OP)) {if (fgetc (OP)!=eof) string++;} printf ("\ n lines =%d\n words =%d\n characters =%d\n", Line (OP), Word (OP), string); fclose (OP); return 0;} /* Row count function */int line (FILE *op) {fseek (OP, 0, seek_set); int lines = 0;while (!feof (OP)) {if (fgetc (OP) = = ' \ n ') line++;} return line;} /* Word number function */int Word (FILE *op) {fseek (OP, 0, seek_set); int word = 0;int Judge = 0;int ch = 0;while (!feof (OP)) {ch = fgetc (OP); F (ch== ' &&judge==1) {judge = 0;word++;} else if (ch!= ') judge = 1;} return word;}
Practice _ File Word statistics.