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

what is void pointer?

1 Answers   Wipro,


What is difference between far and near pointers?

0 Answers  


What are the different types of linkage exist in c?

0 Answers  


What is c mainly used for?

0 Answers  


Explain what is the difference between declaring a variable and defining a variable?

1 Answers  






What are integer variable, floating-point variable and character variable?

0 Answers  


What is the memory allocated by the following definition ? int (*x)();

2 Answers   ADITI,


Write a C program to check a number even or odd, without using any relational, arithmetic operator and any loops.

1 Answers  


What does malloc () calloc () realloc () free () do?

0 Answers  


write a program which the o/p should b in such a way that s triangle if I/p is 3,a Square/rectangle if I/P=4,a pentagon if I/P=5 and so on...forget about the I/P which is less than 3

0 Answers   ADP,


How Many Header Files in c?

2 Answers   TCS,


How #define works?

0 Answers  


Categories