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


Please Help Members By Posting Answers For Below Questions

Is c programming hard?

563


Is swift based on c?

622


difference between Low, Middle, High Level languages in c ?

1618


How can you allocate arrays or structures bigger than 64K?

670


Synonymous with pointer array a) character array b) ragged array c) multiple array d) none

603






What is the use of getchar functions?

659


Is fortran still used today?

591


Write a program to find factorial of a number using recursive function.

632


Why do some versions of toupper act strangely if given an upper-case letter?

622


Do pointers need to be initialized?

546


Given below are three different ways to print the character for ASCII code 88. Which is the correct way1) char c = 88; cout << c << " ";2) cout.put(88);3) cout << char(88) << " "; a) 1 b) 2 c) 3 d) constant

658


Array is an lvalue or not?

620


What is union in c?

622


What does %d do?

703


I have a varargs function which accepts a float parameter?

562