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 Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

When should a type cast not be used?

616


How would you obtain the current time and difference between two times?

718


When the macros gets expanded?

772


Is array a primitive data type in c?

566


How can I list all of the predefined identifiers?

567






Is main is a keyword in c?

598


What does 4d mean in c?

930


C program execution always begins with a) #include b) comment (/*-------*/) c) main() d) declaration instructions

599


What is build process in c?

634


how to find binary of number?

3408


Tell me is null always defined as 0(zero)?

663


Write a program to swap two numbers without using third variable?

808


Why doesn't C support function overloading?

1594


Explain heap and queue.

574


What is void main () in c?

720