December 2005
Beginner to intermediate
618 pages
20h 19m
English
memchr
Searches a memory block for a given byte value
#include <string.h> void *memchr( const void *buffer, intc, size_tn);
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.
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 = '_';Read now
Unlock full access