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

How to write a program for machine which is connected with server for that server automatically wants to catch the time for user of that machine?

1841


What is #define used for in c?

818


What is the usage of the pointer in c?

839


Is it possible to have a function as a parameter in another function?

846


What is function in c with example?

841


how to create duplicate link list using C???

2281


Take an MxN matrice from user and then sum upper diagonal in a variable and lower diagonal in a separate variables. Print the result

1694


stripos — Find position of first occurrence of a case- insensitive string int stripos ( char* haystack, char* needle, int offset ) Returns the numeric position of the first occurrence of needle in the haystack string. Note that the needle may be a string of one or more characters. If needle is not found, stripos() will return -1. The function should not make use of any C library function calls.

2165


What is difference between main and void main?

864


Why malloc is faster than calloc?

814


What library is sizeof in c?

824


What is else if ladder?

807


Explain modulus operator. What are the restrictions of a modulus operator?

824


Can you write the function prototype, definition and mention the other requirements.

890


How do I round numbers?

787