#include<stdio.h> #include<stdlib.h> #include<assert.h> char *my_strchr(const char *dst, char c) { assert(dst); const char *pdst = dst; while (*pdst) { if (*pdst == c) return (char *)pdst; else pdst++; } return NULL; } int main() { char c=0; char arr[40]={0}; char * = NULL; scanf("%c", &c); scanf("%s", arr); str=my_strchr(arr, c); printf("%#p\n",*str); system("pause"); return 0; } #include<stdio.h> #include<stdlib.h> #include<assert.h> char *my_strrchr(const char *src, char c) { assert(src); const char *psrc = src; char *dst = NULL; while (*psrc) { if (*psrc == c) dst =(char *) psrc; psrc++; } return dst; } int main() { char c = 0; char arr[40]; char *place = NULL; scanf("%c%s", &c, arr); place = my_strrchr(arr, c); printf("%#p\n",place); system("pause"); return 0; } //strrstr库里面没有 #include<stdio.h> #include<stdlib.h> #include<assert.h> char *my_strrstr(const char *dst, const char *src) { assert(dst); assert(src); const char *pdst = dst; const char *psrc = src; char *right= NULL; while (*dst) { while (*pdst == *psrc) { if (*pdst== '\0') return right=(char *)dst; else { pdst++; psrc++; } } if (*psrc == '\0') right = (char *)dst; pdst = ++dst; psrc = src; } return right; } int main() { char arr1[50] = { 0 }; char arr2[40] = { 0 }; char *place = NULL; scanf("%s%s",arr1, arr2); place = my_strrstr(arr1, arr2); printf("%#p\n",place); system("pause"); return 0; }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。