Question: #include // I/O library int main() { int t = 0, nc = 0, ns = 0, nd = 0;//t-total characters, nc-number of capital, ns-number

#include // I/O library

int main() { int t = 0, nc = 0, ns = 0, nd = 0;//t-total characters, nc-number of capital, ns-number of small, nd-number of digits FILE* fp; // file pointer char ch; // store characters read from file float pc, ps, pd;//pc-percentage of capital, percentage of small, percentage of digits fopen_s(&fp, "characters.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 t++;//incrementing total number of characters if (ch >= 'A' && ch <= 'Z')//checking for capital letters { nc++;//incrementing number of capital } else if (ch >= 'a' && ch <= 'z')//checking for small letters { ns++;//incrementing number of small } else if (ch >= '0' && ch <= '9')//checking for digits {

nd++;//incrementing number of digits } } // end of reading file while loop //calculating percentage pc = (float)nc / t; ps = (float)ns / t; pd = (float)nd / t; printf("There are %d characters with %.2f%% upper case, %.2f%% lower case, %.2f%% digits", t, pc, ps, pd); fclose(fp); // close file return 0; } // end main

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.

Generate another new text file that your program processes correctly, but that you think might trip up someone elses program. Name that file yourlastname-tricky.txt. Run your program on this file, take a screenshot of the execution result. Describe what the expected output from your tricky test file should be and why you think it is a good test case that might trip up someone else.

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!