0

使用该函数strchr是否可以在字符串中搜索字符串而不是字符

例子:

而不是这个:

int r=strchr("Hello World",'W');

这个可以用吗:

int r=strchr("Hello World","World");
4

3 回答 3

3

使用函数“strchr()”是否可以在字符串中搜索“子字符串”而不是“字符”?

例子 :

而不是这个: int r=strchr("Hello World",'W');

可以使用: int r=strchr("Hello World","World");

不,那strstr()是为了

另请注意,strchr()它不返回int,它返回一个char *指向所搜索字符的指针,或者NULL如果未找到。编译器警告的存在是有原因的......

于 2017-12-12T12:57:31.317 回答
2

没有。你可以使用strstr

char *substring = strstr("Hello World","World");
于 2017-12-12T12:55:43.223 回答
1

为此使用 strstr。

使用此链接作为参考

http://www.cplusplus.com/reference/clibrary/cstring/strstr/

于 2017-12-12T12:57:45.033 回答