English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Bibliothèque standard en C - <string.h>
C 库函数 char *strstr(const char *haystack, const char *needle) 在字符串 haystack 中查找第一次出现字符串 needle 的位置,不包含终止符 '\0'。
下面是 strstr() 函数的声明。
char *strstr(const char *haystack, const char *needle)
haystack -- 要被检索的 C 字符串。
needle -- 在 haystack 字符串内要搜索的小字符串。
该函数返回在 haystack 中第一次出现 needle 字符串的位置,如果未找到则返回 null。
下面的示例演示了 strstr() 函数的用法。
#include <stdio.h> #include <string.h> int main() { const char haystack[20]="oldtoolbag.com"; const char needle[10]="HOOO"; char *ret; ret = strstr(haystack, needle); printf("La sous-chaine est : %s\n", ret); return(0); }
Compilons et exécutons le programme ci-dessus, cela produira le résultat suivant :
La sous-chaine est : HOOO