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

Write the program with at least two functions to solve the following problem. The members of the board of a small university are considering voting for a pay increase for their 10 faculty members. They are considering a pay increase of 8%. Write a program that will prompt for and accept the current salary for each of the faculty members, then calculate and display their individual pay increases. At the end of the program, print the total faculty payroll before and after the pay increase, and the total pay increase involved.

2643


What is a void pointer in c?

602


What is difference between Structure and Unions?

633


I need a sort of an approximate strcmp routine?

654


Can a program have two main functions?

565






write a program in c language to print your bio-data on the screen by using functions.

6239


What the advantages of using Unions?

667


What is the basic structure of c?

551


a function gets called when the function name is followed by a a) semicolon (;) b) period(.) c) ! d) none of the above

860


What is function what are the types of function?

552


pgm to find any error in linklist(in single linklist check whether any node points any of previous nodes instead of next node)

2195


Can the “if” function be used in comparing strings?

583


What is a newline escape sequence?

661


Write programs for String Reversal & Palindrome check

594


a program that can input number of records and can view it again the record

1476