Question
Write a C callable function that counts the number of characters in a string. The function should work for any string and character. The address
Write a C callable function that counts the number of characters in a string. The function should work for any string and character. The address of the string and character to be counted are passed as arguments according to the C function prototype:
extern int count(char *string, char c);
int main(void) { char s[100]; char c; printf("Enter a string of characters: "); scanf("%s", s); printf("Enter a character to count: "); scanf("%c", &c); printf(" The number of %c's in the string %s is %d ", c, s, count(s, c)); return 0; }
Please write the code in C. The function needs to be called as asked.
Examples
Please enter a character : Chegg
enter a character to count : g
Number of g = 2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started