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 ctrl c called?

594


What are qualifiers in c?

573


Why do we use namespace feature?

581


What is multidimensional arrays

631


What should malloc(0) do?

614






What is the heap?

685


WRITE A CODE IN C TO SEARCH A FILE FROM NOTEPAD FILE.

2026


What is a file descriptor in c?

562


Why do we use pointer to pointer in c?

597


Why does notstrcat(string, "!");Work?

643


Why is a semicolon (;) put at the end of every program statement?

626


What language is lisp written in?

618


What is a void pointer in c?

607


What is the condition that is applied with ?: Operator?

663


What are logical errors and how does it differ from syntax errors?

658