直接上code
char *p="add@/devices/platform/0.soc/xxx.dwmmc1/mmc_host/mmc1/mmc1";
char str[128] = "add@/devices/platform/0.soc/xxx.dwmmc1/mmc_host/mmc1/mmc1:aaaa/block/mmcblk1/mmcblk1p1 ACTION=add DEVPATH=xxxxx";
if(strstr(str,p))
{
printf("p:%s\n",p);
}
或者如下写法也是可以的
const char src[20] = "test12345";
const char content[10] = "12";
char *ret;
ret = strstr(src, content);
if (ret == NULL) {
printf("子字符串没找到\n");
} else {
printf("子字符串是: %s\n", ret);
}
运行结果:
$ gcc -o test test.c
$ ./test
子字符串是: 12345
本文通过两个示例展示了如何使用C语言的strstr函数来查找一个字符串是否包含另一个子字符串。第一个示例中,检查了一个长路径字符串是否包含特定设备路径;第二个示例则演示了如何查找并打印出源字符串中包含的特定子字符串。

4094

被折叠的 条评论
为什么被折叠?



