C program to detect the occurrence of a character in a given string

int main()
	char str[20], ch;
	int count = 0, i;
	printf("\nEnter a string : ");
	scanf("%s", &str);
	printf("\nEnter the character to be searched : ");
	scanf("%c", &ch);
	for (i = 0; str[i] != '\0'; i++) {
		if (str[i] == ch)
			scanf("%c", &ch);
	if (count == 0)
		printf("\nCharacter '%c'is not present", ch);
		printf("\nOccurence of character '%c' : %d", ch, count);
	return (0);


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s