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
When can you use a pointer with a function?
Do you know pointer in c?
What is substring in c?
What is meant by initialization and how we initialize a variable?
What are inbuilt functions in c?
What is this infamous null pointer, anyway?
Explain what is the benefit of using #define to declare a constant?
How can I find the modification date and time of a file?
How do you list files in a directory?
What is a memory leak? How to avoid it?
Explain 'bus error'?
What is the difference between array and pointer?
When is a void pointer used?
What is union in c?
What are the different types of C instructions?