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
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.
What is a void pointer in c?
What is difference between Structure and Unions?
I need a sort of an approximate strcmp routine?
Can a program have two main functions?
write a program in c language to print your bio-data on the screen by using functions.
What the advantages of using Unions?
What is the basic structure of c?
a function gets called when the function name is followed by a a) semicolon (;) b) period(.) c) ! d) none of the above
What is function what are the types of function?
pgm to find any error in linklist(in single linklist check whether any node points any of previous nodes instead of next node)
Can the “if” function be used in comparing strings?
What is a newline escape sequence?
Write programs for String Reversal & Palindrome check
a program that can input number of records and can view it again the record