標準/拡張機能 | C/C++ | 依存項目 |
---|---|---|
ISO C |
両方 |
#include <string.h>
void *memchr(const void *buf, int c, size_t count);
memchr() 組み込み関数は、buf が指す最初 の count バイトを検索して、符号なし文字に 変換される c の最初のオカレンスを調べます。検索は、この関数が c を検出するか、count バイトを検査するまで続きます。
正常に実行された場合、memchr() は、buf の c のロケーションへのポインターを戻します。
c が buf の先頭の count バイトの中にない場合、memchr() は NULL を戻します。
⁄* CELEBM11
This example finds the first occurrence of "x" in
the string that you provide.
If it is found, the string that starts with that character is
printed.
If you compile this code as MYPROG, then it could be invoked
like this, with exactly one parameter:
MYPROG skixing
*⁄
#include <stdio.h>
#include <string.h>
int main(int argc, char ** argv)
{
char * result;
if ( argc != 2 )
printf( "Usage: %s string¥n", argv[0] );
else
{
if ((result = (char *)memchr( argv[1], 'x', strlen(argv[1])) ) != NULL)
printf( "The string starting with x is %s¥n", result );
else
printf( "The letter x cannot be found in the string¥n" );
}
}
The string starting with x is xing