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
Is c programming hard?
Is swift based on c?
difference between Low, Middle, High Level languages in c ?
How can you allocate arrays or structures bigger than 64K?
Synonymous with pointer array a) character array b) ragged array c) multiple array d) none
What is the use of getchar functions?
Is fortran still used today?
Write a program to find factorial of a number using recursive function.
Why do some versions of toupper act strangely if given an upper-case letter?
Do pointers need to be initialized?
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
Array is an lvalue or not?
What is union in c?
What does %d do?
I have a varargs function which accepts a float parameter?