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       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
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
write the function int countchtr(char string[],int 
ch);which returns the number of timesthe character ch 
appears in the string. for example the call countchtr("she 
lives in Newyork",'e') would return 3.
 Question Submitted By :: Umayal
I also faced this Question!!     Rank Answer Posted By  
 
  Re: write the function int countchtr(char string[],int ch);which returns the number of timesthe character ch appears in the string. for example the call countchtr("she lives in Newyork",'e') would return 3.
Answer
# 1
#include<stdio.h>
#include<conio.h>
int string(char *,char);
void main()
{
char str[100],ch;
int c;
printf("enter the string :");
gets(str);
printf("enter the character to be searched :");
scanf("5c",&ch);
c=string(&str[0],ch);
printf("the character %c occurs for %d times ",ch,c);
getch();
}
int string(char *a,char ch)
{
int count=0;
  for(int j=0;*a!='\0';j++)
{
   if(*a==ch)
{
count++;
*(a++);
}
}
return count;
}
 
Is This Answer Correct ?    4 Yes 2 No
Vignesh1988i
 
  Re: write the function int countchtr(char string[],int ch);which returns the number of timesthe character ch appears in the string. for example the call countchtr("she lives in Newyork",'e') would return 3.
Answer
# 2
int countchtr(char *str, char ch)
{
   int count=0;
   char *itr = str;
   while (*itr != '\0')
   {
       if(*itr == ch)
       {
          count++
       }
       itr++;
   }
   return count;
}
 
Is This Answer Correct ?    4 Yes 0 No
Goloap
 
 
 
  Re: write the function int countchtr(char string[],int ch);which returns the number of timesthe character ch appears in the string. for example the call countchtr("she lives in Newyork",'e') would return 3.
Answer
# 3
a small change..............

#include<stdio.h>
#include<conio.h>
int string(char *,char);
void main()
{
char str[100],ch;
int c;
printf("enter the string :");
gets(str);
printf("enter the character to be searched :");
scanf("5c",&ch);
c=string(&str[0],ch);
printf("the character %c occurs for %d times ",ch,c);
getch();
}
int string(char *a,char ch)
{
int count=0;
  for(int j=0;*a!='\0';j++)
{
   if(*a==ch)
{
count++;
*a++;
}
}
return count;
}
 
Is This Answer Correct ?    3 Yes 0 No
Vignesh1988i
 
  Re: write the function int countchtr(char string[],int ch);which returns the number of timesthe character ch appears in the string. for example the call countchtr("she lives in Newyork",'e') would return 3.
Answer
# 4
#include<stdio.h>
#include<conio.h>
int string(char *,char);
void main()
{
char str[100],ch;
int c;
printf("enter the string :");
gets(str);
printf("enter the character to be searched :");
scanf("5c",&ch);
c=string(&str[0],ch);
printf("the character %c occurs for %d times ",ch,c);
getch();
}
int string(char *a,char ch)
{
int count=0;
  for(int j=0;*a!='\0';j++)
{
   if(*a==ch)
{
count++;
*(a++);
}
}
return count;
}
 
Is This Answer Correct ?    0 Yes 0 No
Jagjit
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
how to convert an char array to decimal array  3
wats the diference btwen constant pointer and pointer to a constant.pls give examples.  6
what is the output of the following program? #include<stdio.h> void main() { int x=4,y=3,z; z=x-- -y; printf("\n%d %d %d",x,y,z); }  10
what r callback function?  1
how many error occurs in C language ? Wipro11
WHAT IS THE DIFFERANCE BITWIN GETS();AND SCANF();  2
Implement a function that returns the 5th element from the end in a singly linked list of integers in one pass. Microsoft6
can you explain in brief what is "r+" mode in a file... i know that it si used to read and modify rhe existing content.... but explalanation about the file pointer in "r+" mode i wann to know??????????? Cognizent1
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
void main() { int i=5; printf("%d",i+++++i); } ME12
how many argument we can pas in in a function CTS20
Write code for atoi(x) where x is hexadecimal string. Adobe2
1,4,8,13,21,30,36,45,54,63,73,?,?. Franklin-Templeton5
i want to know aptitude questions,technical questions  2
program to find the ASCII value of a number  5
To what value are pointers initialized? 1) NULL 2) Newly allocated memory 3) No action is taken by the compiler to initialize pointers.  2
Main must be written as a.the first function in the program b.Second function in the program c.Last function in the program d.any where in the program TCS12
#include<stdio.h> main() { char s1[]="Ramco"; char s2[]="Systems"; s1=s2; printf("%s",s1); } Find the output CitiGroup4
main() { int x=10,y=15; x=x++; y=++y; printf("%d %d\n",x,y); } output?? Ramco13
How to avoid structure padding in C? Tech-Mahindra4
 
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