Find occurence of a character in a sting.

Answer Posted / anil kumar nahak

void main()
{
char *st,ch;
int i=0,c=0;
printf("\n Enter The String: ");
gets(st);
printf("\n Enter A character For finding occurance: ");
scanf("%c",&ch);

while(st[i]!='\0')
{
if(st[i]==ch)
c++;
i++;
}
printf("\n %c Present In The String %d Times",ch,c);

}

Is This Answer Correct ?    4 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why main is used in c?

684


What is #include stdio h?

786


What is string length in c?

719


Why do we use namespace feature?

679


When should structures be passed by values or by references?

677






What is pointer to pointer in c with example?

640


Differentiate call by value and call by reference?

646


What are the advantages of using Unions?

732


How many keywords are there in c?

712


Differentiate between null and void pointers.

729


Can you please explain the difference between exit() and _exit() function?

698


Explain the difference between malloc() and calloc() function?

684


Explain what is the use of a semicolon (;) at the end of every program statement?

832


Can we use visual studio for c?

646


What are the 4 types of organizational structures?

702