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
What is c token?
What is the use of static variable in c?
Are the expressions * ptr ++ and ++ * ptr same?
What is the advantage of a random access file?
What are different types of operators?
Explain what are global variables and explain how do you declare them?
What is the time and space complexities of merge sort and when is it preferred over quick sort?
What is a scope resolution operator in c?
How can I write data files which can be read on other machines with different word size, byte order, or floating point formats?
Explain is it valid to address one element beyond the end of an array?
what is the structure pointer?
Why do we use int main instead of void main in c?
Device an algorithm for weiler-atherton polygon clipping, where the clipping window can be any specified polygon
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.?
How can type-insensitive macros be created?