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

a small change..............

#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 ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is c method?

769


Write a program to identify if a given binary tree is balanced or not.

948


What are 3 types of structures?

863


What is hashing in c language?

883


How do you write a program which produces its own source code as output?

869


Where static variables are stored in memory in c?

772


How can I make sure that my program is the only one accessing a file?

982


Write a program to implement queue.

904


What is nested structure?

812


c programs are converted into machine language with the help of a) an interpreter b) a compiler c) an operatinf system d) none of the above

1047


What is use of integral promotions in c?

909


How to write a multi-statement macro?

843


How will you delete a node in DLL?

968


Explain what are compound statements?

842


What is a nested formula?

835