在C语言中,可以使用`strstr()`函数来判断一个字符串是否包含另一个子串。`strstr()`函数的原型如下:
```c
char *strstr(const char *haystack, const char *needle);
```
其中,`haystack`是主字符串,`needle`是要查的子串。如果`needle`在`haystack`中存在,`strstr()`函数返回指向`needle`在`haystack`中的首次出现位置的指针;否则返回NULL。
示例代码:
```c
#include <stdio.h>
#include <string.h>
int main() {
    char haystack[] = "hello world";
    char needle[] = "world";子字符串是什么
    char *result;
    result = strstr(haystack, needle);
    if (result != NULL) {
        printf("子串 '%s' 存在于主串 '%s' 中,位置为: %ld
", needle, haystack, result - haystack);
    } else {
        printf("子串 '%s' 不存在于主串 '%s' 中
", needle, haystack);
    }
    return 0;
}
```
在这个示例中,我们使用`strstr()`函数判断子串"world"是否存在于主串"hello world"中,并输出结果。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。