在http://www.cplusplus.com/reference/cstring/strchr/的strchr
参考资料中,提供了这个例子。
/* strchr example */
#include <stdio.h>
#include <string.h>
int main ()
{
char str[] = "This is a sample string";
char * pch;
printf ("Looking for the 's' character in \"%s\"...\n",str);
pch=strchr(str,'s');
while (pch!=NULL)
{
printf ("found at %d\n",pch-str+1);
pch=strchr(pch+1,'s');
}
return 0;
}
为什么从指针中减去char
数组加一会得到一个?(由格式类型表示)如果我删除“ ”,程序将不会执行,直到我更改为.str
char
pch
int
%d
-str
%d
%s