Write a function that takes as parameter a character array, which may contains l
ID: 3760336 • Letter: W
Question
Write a function that takes as parameter a character array, which may contains lowercase, uppercase, digits, and other special symbols (e.g, *, $, ...), and outputs the number of lowercase, uppercase, digits, and special symbol. Please use a character array to store the input string. You can assume the character array is large enough to store all input characters. Also, write a program to test your function. - read and store the input string as a character array - a function to count the number of lowercase, uppercase, digits, and special symbol - a main function to call your function
Explanation / Answer
Answer in c language is below:
#include<stdio.h>
void count(char ch[])
{
int upper = 0, lower = 0,digit=0,special=0;
int i;
for(i = 0; ch[i]!='';i++)
{
if (ch[i] >= 'A' && ch[i] <= 'Z')
upper++;
else if (ch[i] >= 'a' && ch[i] <= 'z')
lower++;
else if(ch[i] >='0' && ch[i] <='9')
digit++;
else if(ch[i]!='*' || ch[i]!='$' || ch[i]!='@' || ch[i]!='!' || ch[i]!='&' || ch[i]!='#' || ch[i]!='^')
special++;
}
printf(" Uppercase Letters : %d", upper);
printf(" Lowercase Letters : %d", lower);
printf(" Digits : %d", digit);
printf(" Special Characters : %d",special);
}
int main()
{
char ch1[80];
printf(" Enter The String : ");
gets(ch1);
count(ch1);
return 1;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.