1. Write the function int countchtr(char string[ ], int ch);
which returns the number of times the character ch appears
in the string.
Example, the call countchtr(“She lives in NEWYORK”, ‘e’)
would return 3.

Answer Posted / vignesh1988i

#include<stdio.h>
#include<conio.h>
int countchtr(char [],char);
void main()
{
char a[20],ch;
int c;
printf("enter the string :");
gets(a);
printf("enter the char. to be :");
scanf("%c",&ch);
c=countchtr(a,ch);
printf("%d",c);
getch();
}
int countchtr(char a[],char ch)
{
int count=0;
for(int i=0;a[i]!='\0';i++)
{
if(a[i]==ch)
count++;
}
return(count);
}



thank u

Is This Answer Correct ?    4 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is equivalent to ++i+++j?

637


What is volatile c?

512


How can you invoke another program from within a C program?

609


A function can make the value of a variable available to another by a) declaring the variable as global variable b) Passing the variable as a parameter to the second function c) Either of the two methods in (A) and (B) d) binary stream

660


What is the role of && operator in a program code?

560






write a C program: To search a file any word which starts with ?a?. If the word following this ?a? starts with a vowel.Then replace this ?a? with ?a? with ?an?. redirect with the output onto an output file.The source file and destination file are specified by the user int the command line.

2445


Can static variables be declared in a header file?

606


which of the following is not a character constant a) 'thank you' b) 'enter values of p, n ,r' c) '23.56E-o3' d) all of the above

1406


What is c mainly used for?

589


Can a void pointer point to a function?

563


How many types of sorting are there in c?

600


What is the difference between if else and switchstatement

1306


What is array within structure?

574


Describe newline escape sequence with a sample program?

639


Compare and contrast compilers from interpreters.

673