I am trying to add a function that will accept a user input of a character and c
ID: 3655041 • Letter: I
Question
I am trying to add a function that will accept a user input of a character and count the number of times it occurs It currently converts the string entered by the user into upper and lower case and counts the number of characters entered. Now i need to get it to count the number times a letter entered by the user appears in the string. #include#include#define MAXNUM 30 int countchar (char []); int main() { char str2[MAXNUM]; int numchar; char str[30]; int i; printf("Please enter in a string of a maximum of 30 letters: "); printf("Please enter in a letter: "); scanf("%s",str); numchar = countchar (str); for(i=0;i<=strlen(str);i++) { if(str[i]>=65&&str[i]<=90) str[i]=str[i]+32; } printf("The string in lower case is: %s ",str); for(i=0;i<=strlen(str);i++) { if(str[i]>=97&&str[i]<=122) str[i]=str[i]-32; } printf("The string in upper case is: %s ",str); printf ("The length of the string is %d characters ", numchar); return 0; } int countchar (char list[]) { int i, count = 0; for(i = 0; list[i] != ''; i++) count++; return (count); }Explanation / Answer
#include #include #include #include char ch=tolower(ch-'A'); using namespace std; int main() { char ch=('a','b','c','d','e','f','g','h','i','j','k','l','M','n','o','P','q','r','s','t','u','v','w','x','y','z'); fstream infile; infile.open("108.txt"); if(ch =='A' || ch =='Z') { coutRelated 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.