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 / vignesh1988i

#include<stdio.h>
#include<conio.h>
int string(char *,char);
void main()
{
char str[100],ch;
int c;
printf("enter the string :");
gets(str);
printf("enter the character to be searched :");
scanf("5c",&ch);
c=string(&str[0],ch);
printf("the character %c occurs for %d times ",ch,c);
getch();
}
int string(char *a,char ch)
{
int count=0;
for(int j=0;*a!='\0';j++)
{
if(*a==ch)
{
count++;
*(a++);
}
}
return count;
}

Is This Answer Correct ?    4 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is c token?

862


What is the use of static variable in c?

858


Are the expressions * ptr ++ and ++ * ptr same?

891


What is the advantage of a random access file?

900


What are different types of operators?

811


Explain what are global variables and explain how do you declare them?

867


What is the time and space complexities of merge sort and when is it preferred over quick sort?

898


What is a scope resolution operator in c?

990


How can I write data files which can be read on other machines with different word size, byte order, or floating point formats?

826


Explain is it valid to address one element beyond the end of an array?

982


what is the structure pointer?

1892


Why do we use int main instead of void main in c?

930


Device an algorithm for weiler-atherton polygon clipping, where the clipping window can be any specified polygon

5737


Function which gives a pointer to a binary trees const an integer value at each code, return function of all the nodes in binary tree.?

856


How can type-insensitive macros be created?

951