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
a small change..............
#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 ? | 3 Yes | 0 No |
Post New Answer View All Answers
Can we change the value of #define in c?
how can i access hard disk address(physical address)? are we access hard disk by using far,near or huge pointer? if yes then please explain.....
Explain how to reverse singly link list.
The performance of an operation in several steps with each step using the output of the preceding step a) recursion b) search c) call by value d) call by reference
What is structure padding and packing in c?
How can I handle floating-point exceptions gracefully?
What is the right type to use for boolean values in c? Is there a standard type?
Tell us something about keyword 'auto'.
How many identifiers are there in c?
How to explain the final year project as a fresher please answer with sample project
Write a program on swapping (100, 50)
Why is it that not all header files are declared in every C program?
What are Macros? What are its advantages and disadvantages?
Why is c faster?
How can I remove the leading spaces from a string?