This is a Sample C Program To Accept A String & Find Out Whether This Character Is Present In The String.
If Present Then Display How Many Times This Character Occurs.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void s(char *p,char hc);
void main()
{
char str[10];
char ch;
clrscr();
printf(" \n \n Enter the string: \t ");
gets(str);
printf(" \n \n Enter the character: \t ");
scanf("%c",&ch);
s(str,ch);
}
void s(char *p,char hc)
{
int a = 0;
int i,l;
l = strlen(p);
for(i = 0; i < l; i++)
{
if ( p[i] == hc)
{
a++;
}
else
continue;
}
printf(" \n \n The Entered Character occurs %d times. ", a);
getch();
}
OUTPUT:
Enter the string: Googleplus
Enter the character: l
The Entered Character occurs 2 times.
ALSO READ:
Sample C Program To Accept A String & Find Out Whether This Character Is Present In The String.
Sample C Program To Accept A String & Display It's Substring.
Sample C Program To Accept A String & Display It's Alternate Characters In Reverse.
Sample C Program To Accept Two Strings & Display The Largest String.
Sample C Program To Accept A String & Display Vowels.
Sample C Program To Accept A String & Display Number Of Vowels.
Sample C Program To Accept A String & Display Number Of Each Vowels.
Comments
Post a Comment
Please share your opinions and suggestions or your experience in the comments section. This way we can all help each other...
Experienced guys can share their resumes at admin@interview-made-easy.com