/查找字符串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; }
相关文章推荐
- 全国计算机等级二级C++第四章习题编程题6 :编写一个函数 char *strfind(char *s, char *t),用于查找字符串t在字符串s中最右边出现的位置,如果没有找到则返回NULL.
- PHP strpos 查找字符串首次出现的位置
- 查找字符串中指定的子串的首次出现的位置
- strchr()查找字符串首次出现字符‘X’的位置
- C 查找字符在字符串首次出现的位置
- C语言strchr()函数:查找某字符在字符串中首次出现的位置
- C语言index()函数:查找字符串并返回首次出现的位置
- C语言strchr()函数:查找某字符在字符串中首次出现的位置
- 编写一个函数 char *strfind(char *s, char *t),用于查找字符串t在字符串s中最右边出现的位置,如果没有找到则返回NULL.
- C语言strchr()函数:查找某字符在字符串中首次出现的位置
- sql查找某个字符串第N次出现的位置的函数(转帖)
- 获取一个字符串Hello world中world首次出现的位置
- [置顶] 在字符串中查找一个特定的字符最后一次出现的位置(即最右边那个)
- 查找指定字符串在字符串中第一次或最后一词出现的位置
- java获取第N次字符串出现的位置,StringUtils详解(判空,去空,比较,查找)
- 从字符串的末尾算起查找出现位置 InStrRev
- 查找字符串出现的位置
- 查找某个字符在字符串中第N次出现的位置
- sql查找某个字符串第N次出现的位置的函数(转帖)
- 【c语言】实现strrchr(查找该字符串最后一次出现的位置)