1. Write the function int countchtr(char string[ ], int ch);
which returns the number of times the character ch appears
in the string.
Example, the call countchtr(“She lives in NEWYORK”, ‘e’)
would return 3.
Answer Posted / ruchi
#include<stdio.h>
#include<conio.h>
#include<string.h>
int countch(char string[], char );
int main()
{
char str[30],c;
int i=0,s;
printf("\nEnter the string ");
while((str[i++]=getchar())!='\n');
printf("\nEnter the word you want to search ");
scanf("%c",&c);
s = countch(str,c);
if(s !=0)
{
printf("\nTHe total occurence of that word in the string
is %d",s);
}
else
{
printf("\nThe word is not present in the string ");
}
getch();
}
int countch(char str[], char c)
{
int i,sum=0,j,d;
i = strlen(str);
for(j=0;j<i;j++)
{ if(str[j]==c)
{
sum++;
}
}
return (sum);
}
Is This Answer Correct ? | 2 Yes | 1 No |
Post New Answer View All Answers
Why do we use namespace feature?
What is non linear data structure in c?
Which header file should you include if you are to develop a function which can accept variable number of arguments?
What is logical error?
What is difference between && and & in c?
What does != Mean in c?
What is New modifiers?
Explain how can I convert a string to a number?
Why dont c comments nest?
#include
What is c system32 taskhostw exe?
What functions are in conio h?
Explain what is the difference between functions abs() and fabs()?
What is #define?
What is bubble sort technique in c?