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


Please Help Members By Posting Answers For Below Questions

Can we change the value of #define in c?

585


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.....

1372


Explain how to reverse singly link list.

606


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

672


What is structure padding and packing in c?

621






How can I handle floating-point exceptions gracefully?

634


What is the right type to use for boolean values in c? Is there a standard type?

564


Tell us something about keyword 'auto'.

666


How many identifiers are there in c?

581


How to explain the final year project as a fresher please answer with sample project

469


Write a program on swapping (100, 50)

638


Why is it that not all header files are declared in every C program?

683


What are Macros? What are its advantages and disadvantages?

649


Why is c faster?

592


How can I remove the leading spaces from a string?

634