7. (20 points) The built in function toupper() takes a single character and retu
ID: 3718160 • Letter: 7
Question
7. (20 points) The built in function toupper() takes a single character and returns the uppercase equivalent. You are to write a function which has a prototype: int CountChar (char s[, char x) s [) is a character string which may be of any length. The function shou return the number of types the character in x (either upper or l occurs in the string s. owercase) For example (this is only an example) the code (put into a properly written program) char al "The Quick Brown Tiger Jumped Over the" char b[l "Really Lazy Zebra" ) char c [ ] = { "Madam, I'm Adam" }; int x,y Z xCountChar (a, t YCountChar (b, z' zCountChar(c, 'M printf("%d %d %din", x, y, z); should print: 3 2 4 Do not write the main program (doing so will cost you points). You should only write the Count Char () function. The function should not have any scanf ), fgets(), or printf () function calls in it. Points will be deducted for using these functions. If you wish/need to write another function which Count Char() calls, that is OK.Explanation / Answer
//////CountChar Function//////////
int CountChar(char s[],char x){
int index = 0,count=0;
char ConvertedChar,comparingChar;
if(x >= 'a' && x <= 'z')
{
ConvertedChar = x - 32; //Converting to Upper
}
else{
ConvertedChar = x + 32; //Converting to lower
}
while (s[index] != '') {
comparingChar = s[index];
if(comparingChar==x || comparingChar==ConvertedChar){
count++; //Compared and counting takesPlaces
}
index++;
}
return count;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.