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
Explain #pragma statements.
What was noalias and what ever happened to it?
When I set a float variable to, say, 3.1, why is printf printing it as 3.0999999?
What is the difference between exit() and _exit() function in c?
What is data type long in c?
What are loops in c?
regarding pointers concept
Is array a primitive data type in c?
Difference between Function to pointer and pointer to function
What are the types of type qualifiers in c?
How can I handle floating-point exceptions gracefully?
What is the most efficient way to store flag values?
What is the use of ?
How do I get an accurate error status return from system on ms-dos?
What is the right type to use for boolean values in c? Is there a standard type?