Search and count for a given char in the string.

#include <stdio.h>

int main(void)
{
char str[80], ch;
int x, cnt;

printf("\nEnter a string : ");
gets(str);
printf("\nEnter a character to search : ");
scanf("%c", &ch);

for(x = cnt = 0 ; str[x] != '\0' ; x++)
if(str[x] == ch) cnt++;

if(cnt == 0)
printf("\nThe character does not occur in the string");
else
printf("\nThe character occurs %d times in the string", cnt);

return 0;
}

No comments:

Post a Comment

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

......from.admin