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   SiteMap shows list of All Categories in this site.
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
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  
 
  Re: 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
# 1
#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 ?    0 Yes 1 No
Vignesh1988i
 
  Re: 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
# 2
#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);
}
 
Is This Answer Correct ?    1 Yes 1 No
Ruchi
 
 
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
In the following control structure which is faster? 1.Switch 2.If-else and which consumes more memory?  4
What is alloca() and why is its use discouraged?  1
Write a routine that prints out a 2-D array in spiral order! Lucent1
How to add two numbers with using function?  2
Reverse the part of the number which is present from position i to j. Print the new number. eg: num=789876 i=2 j=5 778986  1
main() { char *p; p="Hello"; printf("%c\n",*&*p); } ME2
enum day = { jan = 1 ,feb=4, april, may} what is the value of may? a)4 b)5 c)6 d)11 e)none of the above HCL2
how to print "hai" in c?  10
How to add two numbers without using arithmetic operators? Sapient11
what is difference between array and structure? TCS17
what is the stackpointer  2
can we access one file to one directory?  1
in C-programming language without using printf statement can we get output r not ? if yes how and if no also how ?  6
which types of data structure will i use to convert infix to post fix??? IIT3
#include<stdio.h> int SumElement(int *,int); void main(void) { int x[10]; int i=10; for(;i;) { i--; *(x+i)=i; } printf("%d",SumElement(x,10)); } int SumElement(int array[],int size) { int i=0; float sum=0; for(;i<size;i++) sum+=array[i]; return sum; } output? Ramco5
What is C language Terminator? TCS12
main() { char *ptr = "Ramco Systems"; (*ptr)++; printf("%s\n",ptr); ptr++; printf("%s\n",ptr); } Find the Outputs? CitiGroup7
1,4,8,13,21,30,36,45,54,63,73,?,?. Franklin-Templeton5
a=0; b=(a=0)?2:3; a) What will be the value of b? why b) If in 1st stmt a=0 is replaced by -1, b=? c) If in second stmt a=0 is replaced by -1, b=? Geometric-Software6
how we can make 3d venturing graphics on outer interface Microsoft1
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
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