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

why effort estimation is important?

1 Answers  


Which node is more powerful and can handle local information processing or graphics processing?

0 Answers  


If I have a char * variable pointing to the name of a function ..

0 Answers  


What are # preprocessor operator in c?

0 Answers  


Process by which one bit pattern in to another by bit wise operation is?

0 Answers   InterGraph,






Can a void pointer point to a function?

0 Answers  


a formula,a series of steps,or well defined set of rules for solving a problem a) algorithem b) program c) erdiagram d) compiler

0 Answers  


write a C and C++ programme to implement the A,bubble sort B,quick sort C,insertion sort D,sequential search E,binary search

1 Answers   ADP, TCS,


What are loops in c?

0 Answers  


#define f(x) main() { printf("\n%d",f(2+2)); }

5 Answers  


How can we see the Expanded source code and compiled code for our source program in C?

1 Answers  


What is nested structure in c?

0 Answers  


Categories