Write a C program that reads input as a stream of characters

Write a C program that reads input as a stream of characters until encountering EOF (hint: use redirection). Have the program report the number of uppercase characters, the number of lowercase characters, and the number of other characters read. (You can use the functions in ctype.h for this assignment.) Use the attached file infile.txt as input when you submit your assignment.

Solution

Solution:

#include <stdio.h>

#include <ctype.h>

#include <stdlib.h>

int main()

{

char ch;

int otherCount = 0, upperCount = 0, lowerCount = 0,u,l,o;

FILE *fp = fopen(\"infile.txt\", \"r\"); // open file

if (fptr == NULL)

while ((ch = getchar()) != EOF) //while its not the end of the file

{

if(isupper(ch))

{

for (u = 0; u <= ch; u ++)

upperCount++;

printf(\" The number of uppercase entered is:%d\ \", upperCount);

}

elseif (islower(ch))

{

for ( l = 0; l <= ch; l++)

lowerCount++;

printf(\" The number of lowercase entered is: %d\ \", lowerCount);

}

else

{

for ( o = 0; o <= ch; o++)

otherCount++;

printf(\" The number of other characters entered is: %d\ \", otherCount);

}

} //end while

file.close(); //close file

return 0;

}

Write a C program that reads input as a stream of characters until encountering EOF (hint: use redirection). Have the program report the number of uppercase cha
Write a C program that reads input as a stream of characters until encountering EOF (hint: use redirection). Have the program report the number of uppercase cha

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site