Name this program count.c-The program takes the name of an input file as its sin
ID: 3734719 • Letter: N
Question
Name this program count.c-The program takes the name of an input file as its single command line argument and uses a function to count the number of upper-case letters, lower-case letters, and digits found in each string within the file. The main 2. program is shown below. You must write the function counts. This function is passed a string and returns the number of uppercase letters, lowercase letters, and digits through the second, third, and fourth parameters. The file DATA Alabama ./a. out DATA Alabama has 1 uppercase, 6 lowercase, and 0 digits has 4 uppercase, 4 lowercase, and 4 digits 1234crimABCD #%$@#$ has 0 uppercase , 0 lowercase, and 0 digits #8$@#$ | #include #include #include void counts (char *, int *, int *, int ) int main (int arge, char *argvl) ( FILE *fp = fopen (argv [1], char str [100]; fscanf(fp, "%s", str); while feof (fp) "r"); int upper, lower, digit; counts (str, upper, &lower;, &digit;); printf("%s has %d uppercase, %d lowercase, and %d digits ", str, upper, lower, digit) str); fscanf (fp, "%s", return 0;Explanation / Answer
void counts(char *str, int *upper,int *lower,int *digit) {
for(int i=0;i<strlen(str);i++) {
// Checking Upper Case Latter in string
if(str[i]>='A' && str[i]<='Z') {
++*upper;
}
//Checking Lower Case latter in string
else if(str[i]>='a' && str[i]<='z') {
++*lower;
}
//Checking Digit in string (Comaring with its ASCII values)
else {
if(str[i]-'0'>=0 && str[i]-'0'<=9) {
++*digit;
}
}
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.