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
When should a type cast not be used?
How would you obtain the current time and difference between two times?
When the macros gets expanded?
Is array a primitive data type in c?
How can I list all of the predefined identifiers?
Is main is a keyword in c?
What does 4d mean in c?
C program execution always begins with a) #include b) comment (/*-------*/) c) main() d) declaration instructions
What is build process in c?
how to find binary of number?
Tell me is null always defined as 0(zero)?
Write a program to swap two numbers without using third variable?
Why doesn't C support function overloading?
Explain heap and queue.
What is void main () in c?