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 / jagjit
#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 ? | 0 Yes | 0 No |
Post New Answer View All Answers
Can static variables be declared in a header file?
7-Given an index k, return the kth row of the Pascal's triangle. For example, when k = 3, the row is [1,3,3,1]. For reference look at the following standard pascal’s triangle.
What is stack in c?
What are different types of pointers?
What are the two types of functions in c?
main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }
What is the difference between functions abs() and fabs()?
Write a code to generate a series where the next element is the sum of last k terms.
What is cohesion in c?
Can we assign integer value to char in c?
Is there a way to compare two structure variables?
What is n in c?
What is #include stdio h?
Describe the difference between = and == symbols in c programming?
What does emoji p mean?