是否有一个C函数来查找字符串中第二次出现的子字符串?
即字符串 - "213文件状态550访问被拒绝.550访问被拒绝."
此功能将返回"550发现两次"....
Die*_*Epp 11
使用strstr.
int count_550s(char const *str)
{
char const *p = str;
int count;
for (count = 0; ; ++count) {
p = strstr(p, "550");
if (!p)
break;
p++;
}
return count;
}
Run Code Online (Sandbox Code Playgroud)
编辑:忘记"返回".