[C language library function source code]
[This program is compiled in Dev C ++ 4.9.9.2]
# Include <stdlib. h>
/*
Searches at bufferfor the given character, stopping when characteris first found or CNT bytes have been searched through.
Searches for the CH character from the first count bytes of the memory area indicated by the buffer, and stops searching when the CH character is encountered for the first time.
If the call succeeds, a pointer to the CH character is returned; otherwise, null is returned.
*/
Void * my_memchr (const void * buffer, int CH, int count)
{
While (count & (* (unsigned char *) buffer! = (Unsigned char) CH ))
{
Buffer = (unsigned char *) buffer + 1;
Count --;
}
Return (count? (Void *) buffer: NULL );
}
Int main ()
{
Char * STR = "ammana_babi ";
Char * P;
Char ch;
Ch = '9 ';
P = (char *) my_memchr (STR, CH, strlen (STR) + 1 );
If (P = NULL)
Printf ("can't find the character % C! /N ", CH );
Else
Printf ("find the character % C! /N ", * P );
Ch = 'B ';
P = (char *) my_memchr (STR, CH, strlen (STR) + 1 );
If (P = NULL)
Printf ("can't find the character % C! /N ", CH );
Else
Printf ("find the character % C! /N ", * P );
System ("pause ");
Return 0;
}