1. Write the function int countchtr(char string[ ], int ch);
which returns the number of times the character ch appears
in the string.
Example, the call countchtr(“She lives in NEWYORK”, ‘e’)
would return 3.
Answer Posted / vignesh1988i
#include<stdio.h>
#include<conio.h>
int countchtr(char [],char);
void main()
{
char a[20],ch;
int c;
printf("enter the string :");
gets(a);
printf("enter the char. to be :");
scanf("%c",&ch);
c=countchtr(a,ch);
printf("%d",c);
getch();
}
int countchtr(char a[],char ch)
{
int count=0;
for(int i=0;a[i]!='\0';i++)
{
if(a[i]==ch)
count++;
}
return(count);
}
thank u
| Is This Answer Correct ? | 4 Yes | 2 No |
Post New Answer View All Answers
What is c value paradox explain?
a single linked list consists of nodes a to z .print the nodes in reverse order from z to a using recursion
What are register variables in c?
What are structural members?
What is #include stdio h and #include conio h?
What is a nested formula?
What is difference between stdio h and conio h?
How can I rethow can I return a sequence of random numbers which dont repeat at all?
Why enum is used in c?
Explain how do you list a file’s date and time?
Why main is used in c?
What is class and object in c?
How can you increase the size of a dynamically allocated array?
What are the 5 elements of structure?
What is NULL pointer?