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.

Answers were Sorted based on User's Feedback



1. Write the function int countchtr(char string[ ], int ch); which returns the number of times the ..

Answer / vignesh1988i

#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 ?    4 Yes 2 No

1. Write the function int countchtr(char string[ ], int ch); which returns the number of times the ..

Answer / ruchi

#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 ?    2 Yes 1 No

1. Write the function int countchtr(char string[ ], int ch); which returns the number of times the ..

Answer / vadivel t

#include<stdio.h>
#include<conio.h>

int main()
{
char ptr[100]= "She lives in NEWYORK";
char ch;
printf("ENTER THE CHARACTER:\n");
scanf("%c", &ch);
printf("CHAR %c EXIST %d TIME(S)\n",ch, countchtr(ptr, ch));
getch();
}

int countchtr(char *ptr, char ch)
{
int count = 0;
char ch1;
if(ch >= 97 && ch <= 122)
{
ch1 = ch - 32;
}
else if(ch >= 65 && ch <= 96)
{
ch1 = ch + 32;
}
while(*ptr != '\0')
{ if((*ptr == ch) || (*ptr == ch1))
{
count++;
}
ptr++;
}
return count;
}

Is This Answer Correct ?    0 Yes 0 No

1. Write the function int countchtr(char string[ ], int ch); which returns the number of times the ..

Answer / vadivelt

Hi all,

In my post, Answer #3 pls change the statement in if
condition from "ch <= 96" to "ch <= 90"

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

find the output of the following program main() { int x=5, *p; p=&x; printf("%d",++*p); }

10 Answers   Amdocs, TCS,


void main() { //char ch; unsigned char ch; clrscr(); for(ch =0;ch<= 127; ch++) printf(" %c= %d \t ", ch, ch); } output?

4 Answers   Groupon,


When the macros gets expanded?

0 Answers  


WHAT IS INT?

8 Answers   Accenture,


How can I make it pause before closing the program output window?

0 Answers  


what is dangling pointer?

1 Answers   LG Soft,


what is the use of pointers

6 Answers   Adobe, GrapeCity,


What is difference between Structure and Unions?

0 Answers   TISL,


difference between semaphores and mutex?

1 Answers  


void main(int n) { if(n==0) return; main(--n); printf("%d ",n); getch(); } how it work and what will be its output...............it any one know ans plz reply

0 Answers  


Why does everyone say not to use gets?

0 Answers  


What are the advantages and disadvantages of a heap?

0 Answers  


Categories