使用函数 strchr
是否可以在字符串中搜索 substring 而不是 character?
示例:
而不是这个:
int r=strchr("Hello World",'W');
这个可以用吗:
int r=strchr("Hello World","World");
最佳答案
Using the function 'strchr()' is it possible to search for a 'substring' in a string instead of a 'character'?
Example :
Instead of this : int r=strchr("Hello World",'W');
Can this be used : int r=strchr("Hello World","World");
不,那是strstr()
is for .
另请注意 strchr()
不返回 int
,它返回指向所搜索字符的 char *
指针,如果未找到则返回 NULL
。存在编译器警告是有原因的...
关于c - 使用 'srtchr()' 搜索子串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47773154/