write the function int countchtr(char string[],int
ch);which returns the number of timesthe character ch
appears in the string. for example the call countchtr("she
lives in Newyork",'e') would return 3.
Answer Posted / vignesh1988i
#include<stdio.h>
#include<conio.h>
int string(char *,char);
void main()
{
char str[100],ch;
int c;
printf("enter the string :");
gets(str);
printf("enter the character to be searched :");
scanf("5c",&ch);
c=string(&str[0],ch);
printf("the character %c occurs for %d times ",ch,c);
getch();
}
int string(char *a,char ch)
{
int count=0;
for(int j=0;*a!='\0';j++)
{
if(*a==ch)
{
count++;
*(a++);
}
}
return count;
}
| Is This Answer Correct ? | 4 Yes | 2 No |
Post New Answer View All Answers
What is volatile variable how do you declare it?
The % symbol has a special use in a printf statement. Explain how would you place this character as part of the output on the screen?
Can a function argument have default value?
Explain how can I avoid the abort, retry, fail messages?
Is null a keyword in c?
What is break in c?
any function have arguments one or more OR not . it is compulsary a) any function compulsary have one or more arguments b) any function did not have arguments. It is not compulsary c) it is optional it is not compulsary d) none of the above
What is atoi and atof in c?
disply the following menu 1.Disply 2.Copy 3.Append; as per the menu do the file operations 4.Exit
What is the use of gets and puts?
Subtract Two Number Without Using Subtraction Operator
praagnovation
What does the function toupper() do?
What is an lvalue in c?
What does int main () mean?