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

#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 ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can static variables be declared in a header file?

616


7-Given an index k, return the kth row of the Pascal's triangle. For example, when k = 3, the row is [1,3,3,1]. For reference look at the following standard pascal’s triangle.

2222


What is stack in c?

613


What are different types of pointers?

563


What are the two types of functions in c?

564






main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }

909


What is the difference between functions abs() and fabs()?

649


Write a code to generate a series where the next element is the sum of last k terms.

734


What is cohesion in c?

542


Can we assign integer value to char in c?

617


Is there a way to compare two structure variables?

617


What is n in c?

575


What is #include stdio h?

685


Describe the difference between = and == symbols in c programming?

777


What does emoji p mean?

601