/* This program counts the number of characters, letters, digits, and lines in textfile.txt */ #include int main (void) { FILE *infile; char ch; int characters=0, letters=0; int digits=0, others=0; int status; infile = fopen("textfile.txt", "r"); if (infile == NULL) printf("Cannot open textfile.txt\n"); status = fscanf(infile, "%c", &ch); while (status != EOF) { characters++; if ((ch>='A' && ch<='Z') || (ch>='a' && ch<='z')) letters++; else if (ch>='0' && ch<='9') digits++; else others++; status = fscanf(infile, "%c", &ch); } printf("Characters = %d\nLetters = %d\n", characters, letters); printf("Digits = %d\nOthers = %d\n", digits, others); fclose(infile); return 0; }