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

Is it possible to pass an entire structure to functions?

778


What is the data segment that is followed by c?

843


write a program to find the given number is prime or not

4300


WHAT IS THE DEFINATION OF IN TECHNOLOGY AND OFF TECHNOLOGY ?

2107


What is a spanning Tree?

1257


What are the different types of endless loops?

843


Q.1 write aprogram to stack using linklist o insert 40 items? Q.2 write a program to implement circular queue with help of linklist?

1820


Explain union. What are its advantages?

827


What is difference between Structure and Unions?

883


Explain what will the preprocessor do for a program?

809


What are the 4 types of programming language?

779


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

900


How #define works?

853


What is d scanf?

801


Tell me is null always defined as 0(zero)?

849