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                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
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
 
What is difference between the following 2 lines…. int temp = (int)(0x00); int temp = (0x00int); Bosch3
what does the following code do? fn(int n,int p,int r) { static int a=p; switch(n){ case 4:a+=a*r; case 3:a+=a*r; case 2:a+=a*r; case 1:a+=a*r; } } a.computes simple interest for one year b.computes amount on compound interest for 1 to 4 years c.computes simple interest for four year d.computes compound interst for 1 year TCS4
Function to find the given number is a power of 2 or not? Motorola12
how many times of error occur in C  7
What is the output for the following program #include<stdio.h> main() { char a[5][5],flag; a[0][0]='A'; flag=((a==*a)&&(*a==a[0])); printf("%d\n",flag); } ADITI5
main() { char *p1="Name"; char *p2; p2=(char *)malloc(20); while(*p2++=*p1++); printf("%s\n",p2); } what is the output? Ramco4
Is the C language is the portable language...If yes...Then Why...and if not then what is problem so it is not a Portable language..??? TCS1
how many keywords do C compile? Microsoft2
a number is perfect if it is equal to the sum of its proper divisor.. 6 is perfect number coz its proper divisors are 1,2 and three.. and 1+2+3=6... a number is deficient if the sum of its proper divisor is less than the number.. sample: 8 is deficient, coz its proper divisors are 1,2 and 4, and 1+2+4=7. abundant number, if the sum of its proper divisor is greater than the number.. sample..12 is abundant coz 1+2+3+4+6=16 which is geater than 12. now write a program that prompts the user for a number, then determines whether the number is perfect,deficient and abundant..  1
what r callback function?  1
Consider a language that does not have arrays but does have stacks as a data type.and PUSH POP..are all defined .Show how a one dimensional array can be implemented by using two stacks. Google3
how we can make 3d venturing graphics on outer interface Microsoft1
Is the following code legal? struct a { int x; struct a b; }  3
How to write a program for swapping two strings without using 3rd variable and without using string functions. iGate5
main() { char *p1="Name"; char *p2; p2=(char *)malloc(20); while(*p2++=*p1++); printf("%s\n",p2); } CitiGroup4
in C-programming language without using printf statement can we get output r not ? if yes how and if no also how ?  6
write a program to display the array elements in reverse order in c language  6
what is link list?  2
what is the output of the following program? main() { int i=-1,j=-1,k=0,l=2,m; m=i++&&j++&&k++||l++; printf("%d %d %d %d %d",i,j,k,l,m); }  7
#include main() { int i=1,j=2; switch(i) { case 1: printf("GOOD"); break; case j: printf("BAD"); break; } } ME5
 
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