猿问

检查C中的字符串中是否存在子字符串

检查C中的字符串中是否存在子字符串

我正在尝试检查字符串是否在C中包含子字符串,例如:


char *sent = "this is my sample example";

char *word = "sample";

if (/* sentence contains word */) {

    /* .. */

}

用什么代替string::findC ++?


largeQ
浏览 769回答 4
4回答

守候你守候我

if(strstr(sent, word) != NULL) {    /* ... */}注意,如果找到strstr单词,sent则返回指向单词in的指针word。
随时随地看视频慕课网APP
我要回答