C Reference String Operation: memchr()

The memchr() function returns a pointer to the first occurrence of c in the first n bytes of a memory area.


void *memchr(const void *s, int c, size_t n);

If c does not occur, a null pointer is returned.

memchr() source code example:


		char line[100];
		strcpy(line, "aaabccc");

		if( memchr(line,'b',strlen(line)) == NULL )
			printf("b not found\n");
			printf("b is found\n");

Output of the example:

	b is found

This entry was posted in C Reference string.h Functions. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed. Tweet This! Tweet This! or use to share this post with others.

Comments are closed.