#navi(contents-page-name): No such page: 文字列

 指定した文字列が存在する位置を返却する・strstr

strstr関数は引数で指定した文字列が存在した場合、存在した場所のポインタ値を返却します。
以下にCサンプルコードと実行例を記します。

c-top.html is not found or not readable.

関連記事

strstr書式

strstrの書式を以下に記します。

strstrのCサンプルコード

&ref(): File not found: "strstr.c" at page "文字列/指定した文字列が存在する位置を返却する・strstr"; (改行コードLF)

#include <stdio.h>
#include <string.h>

int main(void)
{
    char *s = "abcdefghijklmnopqrstuvwxyz";
    char *p;

    p = strstr(s, "def");
    if (p != NULL) {
      printf("%s\n", p);
    }

    p = strstr(s, "fed");
    if (p != NULL) {
      printf("%s\n", p);
    }
    else {
      printf("fed string is not found.\n");
    }

    return 0;
}

strstrのCサンプルコードの実行結果

コンパイルし実行した結果を以下に記します。

$ gcc strstr.c -o strstr
$ ./strstr 
defghijklmnopqrstuvwxyz
fed string is not found.

以上、strstr関数のCサンプルコードでした。

c-btm.html is not found or not readable.

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS