memchr


memchr

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( )



C(c) In a Nutshell
C in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596006977
EAN: 2147483647
Year: 2006
Pages: 473

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net