标签:mystrchr
字符查找函数strchr
char *mystrchr(const char *str, const char c) { char *p = NULL; for (char*newp = str; *newp != '\0'; newp++) { if (*newp==c) { p = newp;//一个一个的查找 break; } } return p; } char *mystrchrdg(const char *str, const char c) { if (*str!='\0') { return NULL; } else { if (*str==c) { return str;//返回指针 } mystrchrdg(++str, c);//循环区域终止 } } //mystrchr void main() { char *pstr1 = mystrchr("zrf is rocket", 'z'); char *pstr2 = <span style="font-family: Arial, Helvetica, sans-serif;">mystrchrdg</span>("zrf is rocket", 'A'); printf("pstr2=%s\n", pstr2); if (pstr1 == NULL) { printf("can not find"); } else { printf("can find %p 存在此字符:%c\n", pstr1, *pstr1); } system("pause"); }
版权声明:本文为博主原创文章,欢迎指出代码不良之处,及提出代码优化方案。欢迎指点,黑夜代码,拼命奋斗,努力更新中......
标签:mystrchr
原文地址:http://blog.csdn.net/zhouruifu2015/article/details/47694749