您的位置:首页 > 其它

/查找字符串str中首次出现c的位置

2013-04-29 20:58 288 查看
#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐