新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
#include#include #include 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 #include #include 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 #include #include 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; }