Programming with C

⌘K
  1. Home
  2. Docs
  3. Programming with C
  4. Functions and Pointers
  5. Built-in functions
  6. Scan String

Scan String

Use of strchr( ) function

#include <stdio.h>
#include<string.h>
int main()
{
	char s1[100],ch='a';
	char *ptr;
	puts("Enter string1");
	gets(s1);
	ptr = strchr(s1,ch);
	if(ptr == NULL)
	{
	    puts("character not present");
	}
	else
	{
	    printf("string present at %d",ptr-s1);
	}
	return 0;
}

Output

Enter string1
Hello all
string present at 6

Views: 0

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments