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
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?
What is #define used for in c?
What is the usage of the pointer in c?
Is it possible to have a function as a parameter in another function?
What is function in c with example?
how to create duplicate link list using C???
Take an MxN matrice from user and then sum upper diagonal in a variable and lower diagonal in a separate variables. Print the result
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.
What is difference between main and void main?
Why malloc is faster than calloc?
What library is sizeof in c?
What is else if ladder?
Explain modulus operator. What are the restrictions of a modulus operator?
Can you write the function prototype, definition and mention the other requirements.
How do I round numbers?