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
How to write c functions that modify head pointer of a linked list?
What is the explanation for prototype function in c?
write a program in c language to print your bio-data on the screen by using functions.
Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.
What is volatile keyword in c?
What are the different categories of functions in c?
Why is structure padding done in c?
What is typedef example?
Can variables be declared anywhere in c?
What is zero based addressing?
Explain what is page thrashing?
Do you know the difference between malloc() and calloc() function?
Do you know the difference between exit() and _exit() function in c?
Define circular linked list.
Why malloc is faster than calloc?