Question: // filereader.c // CS 351 // // Demonstrate reading text file character by character #include // I/O library int main() { FILE* fp; // file

// filereader.c

// CS 351

//

// Demonstrate reading text file character by character

#include // I/O library

int main()

{

FILE* fp; // file pointer

char ch; // store characters read from file

fp = fopen("input.txt", "r"); // open file for reading

// Visual Studio users: you may need to use fopen_s() as shown below or disable the warning on fopen()

//fopen_s(&fp, "input.txt", "r"); // open file for reading

if( fp == NULL ) { // if open failed

printf("Error: can't find data file. Abort program now. ");

return 1; // terminate now

}

// read from file

while ( (ch = fgetc(fp)) != EOF ) { // read one char, go into the loop if not EOF

// 1. process this char

printf("%c", ch); // just print on screen

} // end of reading file while loop

fclose(fp); // close file

return 0;

} // end main

Change the program so that it outputs the percentage of uppercase characters (A-Z), the percentage of lowercase characters (a-z), and the percentage of digits (0-9) in the text file. Note that these percentages will NOT add up to 100! For example, in the highlighted purpose sentence above, there are 83 characters: 3 upper case, 61 lowercase, 1 digit, plus spaces and punctuation. Your program should just print a message like this:

There are 83 characters, with 3.61% upper case, 73.49% lower case and 1.20% digits.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!