Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please explain why the answer is what is is thoroughly. I am trying to study for my test. I will make sure to thumbs up!
Please explain why the answer is what is is thoroughly. I am trying to study for my test. I will make sure to thumbs up! thank you very much for your time
int count_characters(char *filename) {
char str[1001]; FILE* pFile; int count = 0;
pFile = fopen(filename, "r");
if (pFile == NULL) {
printf ("Error opening file ");
return 0; }
while ( fgets (str, MAX_LEN, pFile ) != NULL ) {
count += strlen(str); }
fclose(pFile); return count;
}
16. Write the following function: int count characters (const char filename int n) The function should return the number of characters in the text file whose name is filename. If there is no character in the file or the file does not exit, the function should return 0. Assume the maximum number of characters in each line is 1000Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started