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 a constant?
What is the deal on sprintf_s return value?
Is r written in c?
When should a far pointer be used?
How can you tell whether two strings are the same?
Write a program with dynamically allocation of variable.
Explain threaded binary trees?
What is const volatile variable in c?
What is file in c preprocessor?
What library is sizeof in c?
Can you assign a different address to an array tag?
All technical questions
How main function is called in c?
What is #error and use of it?
Can we access array using pointer in c language?