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 break in c?

842


What is the process to generate random numbers in c programming language?

923


What is wrong in this statement?

846


Why is #define used?

1049


Write a C program on Centralized OLTP, Decentralized OLTP using locking mechanism, Semaphore using locking mechanism, Shared memory, message queues, channel of communication, sockets and a simple program on Saving bank application program using OLTP in IPC?

2475


What is a program?

956


Difference between Shallow copy and Deep copy?

1824


Explain what are multidimensional arrays?

858


can we have joblib in a proc ?

1978


Explain pointer. What are function pointers in C?

863


How can a number be converted to a string?

968


Explain what is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?

881


What are the functions to open and close the file in c language?

841


When is the “void” keyword used in a function?

1201


Explain pointers in c programming?

896