strstr関数は引数で指定した文字列が存在した場合、存在した場所のポインタ値を返却します。
以下にCサンプルコードと実行例を記します。
strstrの書式を以下に記します。
#include <string.h>
char *strstr(const char *haystack, const char *needle);
&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; }
コンパイルし実行した結果を以下に記します。
$ gcc strstr.c -o strstr $ ./strstr defghijklmnopqrstuvwxyz fed string is not found.
以上、strstr関数のCサンプルコードでした。
c-btm.html is not found or not readable.