memchr( ) function: Finding a character in a buffer.
#include <string.h>
#include <stdio.h>
char buf[35];
char *ptr;
int main( )
{
strcpy(buf,"This is a fine day for a search." );
ptr=(char *)memchr(buf,'f',35);
if (ptr != NULL)
printf("character found at location: %d\n",
ptr-buf+1);
else
printf("character not found.\n");
return (0);
}
Related examples in the same category