write the function int countchtr(char string[],int
ch);which returns the number of timesthe character ch
appears in the string. for 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 ? | 1 Yes | 0 No |
Post New Answer View All Answers
how do you execute a c program in unix.
What is c token?
Explain the use of fflush() function?
Explain data types & how many data types supported by c?
How to get string length of given string in c?
What is local and global variable in c?
What are types of preprocessor in c?
What is c++ used for today?
When should volatile modifier be used?
What is the scope of local variable in c?
What is the best way to store flag values in a program?
Differentiate between a for loop and a while loop? What are it uses?
What's the difference between constant char *p and char * constant p?
What is the difference between declaring a variable by constant keyword and #define ing that variable?
Stimulate calculator using Switch-case-default statement for two numbers