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
What is meant by preprocessor in c?
Is there any algorithm to search a string in link list in the minimum time?(please do not suggest the usual method of traversing the link list)
What does stand for?
I need a help with a program: Write a C program that uses data input in determining the whole of points A and a whole of circles B. Find two points in A so that the line which passes through them, cut through the maximum number of circles.
What is the deal on sprintf_s return value?
By using C language input a date into it and if it is right?
ATM machine and railway reservation class/object diagram
Explain the array representation of a binary tree in C.
What are runtime error?
What are type modifiers in c?
which is an algorithm for sorting in a growing Lexicographic order
Can static variables be declared in a header file?
Is multithreading possible in c?
What is the purpose of type declarations?
What is formal argument?