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


Please Help Members By Posting Answers For Below Questions

Why do we use namespace feature?

573


What is non linear data structure in c?

561


Which header file should you include if you are to develop a function which can accept variable number of arguments?

795


What is logical error?

594


What is difference between && and & in c?

563






What does != Mean in c?

579


What is New modifiers?

657


Explain how can I convert a string to a number?

636


Why dont c comments nest?

611


#include int main(){ int i=10; int *ptr=&i; *ptr=(int *)20; printf("%d",i); return 0; } Output: 20 can anyone explain how came the output is 20

1253


What is c system32 taskhostw exe?

578


What functions are in conio h?

647


Explain what is the difference between functions abs() and fabs()?

611


What is #define?

569


What is bubble sort technique in c?

578