|
|
1.1 ! root 1: #include <stdio.h> ! 2: ! 3: main() ! 4: { ! 5: FILE *fp; ! 6: int ch; ! 7: int filename[20]; ! 8: int nlines = 0; ! 9: int nsents = 0; ! 10: ! 11: printf("Enter file to test: "); ! 12: gets(filename); ! 13: ! 14: if ((fp = fopen(filename,"r")) == NULL) { ! 15: printf("Cannot open %s.\n", filename); ! 16: exit(1); ! 17: } ! 18: while ((ch = fgetc(fp)) != EOF) { ! 19: if (ch == '\n') ! 20: ++nlines; ! 21: else ! 22: if (ch == '.' || ch == '!' ! 23: || ch == '?') { ! 24: if ((ch = fgetc(fp)) != '.') ! 25: ++nsents; ! 26: else ! 27: while ! 28: ((ch=fgetc(fp)) == '.') ! 29: ; ! 30: ungetc(ch, fp); ! 31: } ! 32: } ! 33: printf("%d line(s), %d sentence(s).\n", nlines, nsents); ! 34: } ! 35:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.