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

c - This program is a modification of one you did for lab six. Th ts single comm

ID: 3594440 • Letter: C

Question

c - This program is a modification of one you did for lab six. Th ts single command line argument and prints the number of upper- case letters, 2. e program takes Name this program count. the name of an input file as lower case letters, and digits found in each word. No word will ever be longer than 50 characters. A sample command linea execution is shown below The file DATA ./a.out DATA AlAbAmA4 Est. 1831 1 uppercase, 2 lowercase, 4 digits Crimson 1 uppercase, 6 lowercase, 0 digits TIDE#1-4 uppercase, 0 lowercase , 1 digits AlAbAmA Est. 1831 Crimson TIDE#1 - 4 uppercase, 3 lowercase, 0 digits . Your program should confirm the input file exists (exit with an appropriate error message if it does not). n to count the number of uppercase, lowercase, and digits in a given word. The function must use the signature shown below void countC ase (char*,int*,int *,int *) lowercase letters, and digits to This function passes a string and returns the number of uppercase letters, the calling routine through the second, third, and fourth parameters.

Explanation / Answer

#include <stdio.h>

#include <stdlib.h>

void countCase( char *word , int *upper, int *lower, int *digit )

{

int i = 0;

while ( word[i] != '' && i < 50 )

{

if( word[i] >=48 && word[i] <= 57 )

*digit = *digit + 1;

else if ( word[i] >= 65 && word[i] <= 90 )

*upper = *upper + 1;

else if ( word[i] >=97 && word[i] <= 122 )

*lower = *lower + 1;

}

}

int main(int argc, char *argv[])

{

File *inFile; /* pointer to input file */

char word[50]; /* storing each word */

int l =0 ,u =0, d=0; /* num of upper ,lower and digis */

inFile = fopen( argv[1], 'r' ); /* opening the file */

if( !inFile )

return -1;

while ( strlen( fgets( word, 50, inFile )) > 0 ) /* readinfg from file pointer */

{

/* calling countCase to calculate values */

countCase( word, &l, &u, &d );

/* printing the values */

printf("%s - ",word);

printf("%d uppercase, ",u);

printf("%d lowercase, ",l);

printf("%d digits ",d);

/* re initializing to zero */

l =0;

u =0;

d =0;

}

/* closing the file */

fclose(inFile);

return 0;

}

/* hope this helps, if any queries please comment */

/* thank you */

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote