Searches a memory block for a given byte value
#include <string.h>
void *memchr ( const void *buffer , int c , size_t n );
The memchr( ) function searches for a byte with the value of c in a buffer of n bytes beginning at the address in the pointer argument buffer. The function's return value is a pointer to the first occurrence of the specified character in the buffer, or a null pointer if the character does not occur within the specified number of bytes. The type size_t is defined in string.h (and other header files), usually as unsigned int.
Example
char *found, buffer[4096] = "";
int ch = ' ';
fgets( buffer, sizeof(buffer), stdin );
/* Replace any spaces in the string read with underscores: */
while (( found = memchr( buffer, ch, strlen(buffer) )) != NULL )
*found = '_';
See Also
strchr( ), wmemchr( )
|