kazmax - Linux で自宅サーバー

strstr - ライブラリコールの説明 - Linux コマンド集 一覧表

  1. 名前
  2. 書式
  3. 説明
  4. 返り値
  5. バグ
  6. 準拠
  7. 関連項目

名前

strstr - 部分文字列の位置を示す

書式

#include <string.h>

char *strstr(const char *haystack, const char *needle);
#define _GNU_SOURCE
#include <string.h>
char *strcasestr(const char *haystack, const char *needle);

説明

strstr () 関数は、部分文字列 needle が文字列 haystack 中 で最初に現れる位置を見つける。 文字列を終端する \0' 文字は比較されない。
strcasestr () 関数は strstr () 関数と同様だが、 両方の引数に対して大文字小文字を無視する。

返り値

これらの関数は、部分文字列の開始を指すポインタを返し、 もし部分文字列が見つからない場合は NULL を返す。

バグ

Linux libc の初期のバージョン(4.5.26 まで)は strstr () 関数の needle 引数に空文字列を指定できない。 最近のバージョン(4.6.27 以降)は正しく動作し、 needle が空の時は haystack を返す。

準拠

strstr () 関数は C89 と C99 に準拠している。 strcasestr () 関数は非標準拡張である。

関連項目