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 / vignesh1988i
#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 ? | 4 Yes | 2 No |
Post New Answer View All Answers
What is ctrl c called?
What are qualifiers in c?
Why do we use namespace feature?
What is multidimensional arrays
What should malloc(0) do?
What is the heap?
WRITE A CODE IN C TO SEARCH A FILE FROM NOTEPAD FILE.
What is a file descriptor in c?
Why do we use pointer to pointer in c?
Why does notstrcat(string, "!");Work?
Why is a semicolon (;) put at the end of every program statement?
What language is lisp written in?
What is a void pointer in c?
What is the condition that is applied with ?: Operator?
What are logical errors and how does it differ from syntax errors?