#include <iostream>
#include <assert.h>
using namespace std;
//查找字符串str中首次出现c的位置
int strchr(char *str, char c)
{
assert(str != NULL); //断言保证传进来的参数不是空
int position = 1;
while ( *str != '\0' )
{
if (*str == c)
{
return position;
}
++str;
++position;
}
return -1;
}
int main(void)
{
char *s = "hello world";
char *t = "hello";
//char a[10] = {0};
cout<<strchr(t,'l');
system("pause");
return 0;
}/查找字符串str中首次出现c的位置
最新推荐文章于 2022-11-02 19:21:24 发布
2205

被折叠的 条评论
为什么被折叠?



