【发布时间】:2025-11-22 01:35:01
【问题描述】:
使用函数strchr是否可以在字符串中搜索子字符串而不是字符?
示例:
而不是这个:
int r=strchr("Hello World",'W');
这个可以用吗:
int r=strchr("Hello World","World");
【问题讨论】:
标签: c string substring string-search strchr
使用函数strchr是否可以在字符串中搜索子字符串而不是字符?
示例:
而不是这个:
int r=strchr("Hello World",'W');
这个可以用吗:
int r=strchr("Hello World","World");
【问题讨论】:
标签: c string substring string-search strchr
不。您可以为此使用strstr
char *substring = strstr("Hello World","World");
【讨论】:
【讨论】:
使用函数 'strchr()' 是否可以搜索 字符串中的“子字符串”而不是“字符”?
示例:
而不是这个:int r=strchr("Hello World",'W');
这个可以用吗:int r=strchr("Hello World","World");
不,那是strstr() is for。
还要注意strchr() 不返回int,它返回一个指向搜索字符的char * 指针,如果没有找到则返回NULL。存在编译器警告是有原因的...
【讨论】:
'\0'-终止的字符串,是的。