直接上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