Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C Program This program repeatedly reads strings from standard input, halting whe

ID: 3589954 • Letter: C

Question

C Program

This program repeatedly reads strings from standard input, halting when endof-file is reached. For each string, it calls a function, countCase, that takes the string and counts the number of upper-case and lower-case characters in the string, returning a count of upper-case and lower-case characters through the last two parameters. Your main routine should then print the number of uppercase and lowercase characters in that string. The function signature for countCase is shown below: void countCase(char *, int *, int *); A sample execution is shown below. User Input: Alabama CRImSON TidE UA Program Output: Alabama: 1 uppercase, 6 lowercase CRImSON: 6 uppercase, 1 lowercase TidE: 2 uppercase, 2 lowercase UA: 2 uppercase, 0 lowercase 2.

Explanation / Answer

#include<stdio.h>

int countCase(char *world, int *upper, int *lower)
{
     *upper=*lower=0;
     int i=0;
     while(world[i]!=0) {
        if((world[i]>=65) && (world[i]<=90)) *upper=*upper+1;
        if((world[i]>=97) && (world[i]<=122)) *lower=*lower+1;
        i=i+1;
    }
     return 0;
}

int main()
{
    char line[1000], world[100];
    int i, j, eolFound=0, upper, lower;
    printf("Enter String:");
    scanf("%[^ ]",line);
  
    i=0; j=0;
    while(!eolFound) {
        switch(line[i])
           {
             case ' ': world[j]=0;
                       countCase(world, &upper, &lower);
                       printf("%s: %d uppercase, %d lowercase ", world, upper, lower);
                       j=0;
                       break;
             case 0: eolFound=1; break;
             default: world[j]=line[i]; j=j+1; break;
           }
        i=i+1;
    }
   return 0;
}