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
What is c method?
Write a program to identify if a given binary tree is balanced or not.
What are 3 types of structures?
What is hashing in c language?
How do you write a program which produces its own source code as output?
Where static variables are stored in memory in c?
How can I make sure that my program is the only one accessing a file?
Write a program to implement queue.
What is nested structure?
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
What is use of integral promotions in c?
How to write a multi-statement macro?
How will you delete a node in DLL?
Explain what are compound statements?
What is a nested formula?