Program for searching a character in a string.

#include <stdio.h>
#include <conio.h>
void main()
{
char str[20],ch;
int cnt=0,i;
clrscr();
printf("\n\n\n\t\t Program for searching a character in a string");
printf("\n\n\n\t\t\t Enter a string = ");
scanf("%s",&str);
printf("\n\t\t\t Enter the character to search = ");
flushall();
scanf("%c",&ch);
for(i=0;str[i]!='\0';i++)
{
if(str[i]==ch)
cnt++;
}
if(cnt==0)
printf("\n\n\t\t\t The character '%c' is not found in the string...",ch);
else
printf("\n\n\t\t\t The character '%c' is occurring %d times in the string.",ch,cnt);
getch();
}

No comments:

Post a Comment

kiss on google ads if you are anonymous because your ip is trackable.thank you.

......from.admin