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
Is it possible to pass an entire structure to functions?
What is the data segment that is followed by c?
write a program to find the given number is prime or not
WHAT IS THE DEFINATION OF IN TECHNOLOGY AND OFF TECHNOLOGY ?
What is a spanning Tree?
What are the different types of endless loops?
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?
Explain union. What are its advantages?
What is difference between Structure and Unions?
Explain what will the preprocessor do for a program?
What are the 4 types of programming language?
Why does notstrcat(string, "!");Work?
How #define works?
What is d scanf?
Tell me is null always defined as 0(zero)?