ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories >> Software >> Programming-Languages >> C
 
 
 
Question
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.
 Question Submitted By :: Karthi
I also faced this Question!!     Rank Answer Posted By  
 
Answer
#include<stdio.h>
#include<conio.h>
#include<string.h>
int countch(char string[], char );
int main()
{
    char str[30],c;
    int i=0,s;
    printf("\nEnter the string ");
    while((str[i++]=getchar())!='\n');
    printf("\nEnter the word you want to search ");
    scanf("%c",&c);
    s = countch(str,c);
    if(s !=0)
    {
	 printf("\nTHe total occurence of that word in the string
is %d",s);
    }
    else
    {
	printf("\nThe word is not present in the string ");
    }
    getch();
}

int countch(char str[], char c)
{
    int i,sum=0,j,d;
    i = strlen(str);
    for(j=0;j<i;j++)
    {               if(str[j]==c)
                    {
					sum++;
		    }
}
return (sum);
}
 
0
Ruchi
 
View All Answers
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com