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 / jagjit
#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 ? | 0 Yes | 0 No |
Post New Answer View All Answers
What are pointers really good for, anyway?
develop algorithms to add polynomials (i) in one variable
Explain how do you convert strings to numbers in c?
Which is better pointer or array?
What is the purpose of main() function?
When should I declare a function?
How to write a multi-statement macro?
What does %2f mean in c?
How many levels deep can include files be nested?
How the c program is executed?
What is Dynamic memory allocation in C? Name the dynamic allocation functions.
What does sizeof return c?
how to count no of words,characters,lines in a paragraph.
How do I get an accurate error status return from system on ms-dos?
Explain null pointer.