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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!