write the function int countchtr(char string[],int
ch);which returns the number of timesthe character ch
appears in the string. for example the call countchtr("she
lives in Newyork",'e') would return 3.

Answer Posted / goloap

int countchtr(char *str, char ch)
{
int count=0;
char *itr = str;
while (*itr != '\0')
{
if(*itr == ch)
{
count++
}
itr++;
}
return count;
}

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is c mainly used for?

597


What does a derived class inherit from a base class a) Only the Public members of the base class b) Only the Protected members of the base class c) Both the Public and the Protected members of the base class d) .c file

668


Difference between linking and loading?

693


What is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?

729


How can I get back to the interactive keyboard if stdin is redirected?

670






What could possibly be the problem if a valid function name such as tolower() is being reported by the C compiler as undefined?

746


What is class and object in c?

589


write a program to copy the string using switch case?

2401


What is the most efficient way to store flag values?

688


What is variable and explain rules to declare variable in c?

554


State the difference between realloc and free.

635


What is the difference between a free-standing and a hosted environment?

640


How can I do graphics in c?

595


is it possible to create your own header files?

638


To print the pattern 1 2 3 4 5 10 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9

2184