#include <stdio.h> #include <stdlib.h> #include <assert.h>char *my_strchr (Const char &NBSP;*DST,&NBSP;CHAR&NBSP;C) {assert (DST);const char *pdst = dst;while (*PDST) {if (*pdst == c) return (char *) pdst;elsepdst++;} Return null;} Int main () {char c=0;char arr[40]={0};char * = null;scanf ("%c", &c); scanf ("%s", arr), STR=MY_STRCHR (arr, c);p rintf ("% #p \ n", *str); System ("pause"); return 0;} #include <stdio.h> #include <stdlib.h> #include <assert.h>char *my_strrchr (Const char &NBSP;*SRC,&NBSP;CHAR&NBSP;C) {assert (SRC); const char *psrc = src;char *dst = NULL;while (*PSRC) {if (*psrc == c) dst = (char *) psrc;psrc++;} RETURN&NBSP;DST;} Int main () {char c = 0;char arr[40];char *place = null;scanf ("%c%s", &c, arr);p LACE&NBSP;=&NBSP;MY_STRRCHR(arr, c);p rintf ("% #p \ n", place); System ("pause"); return 0;} There is no #include<stdio.h> in the Strrstr library #include <stdlib.h> #include <assert.h>char *my_strrstr ( CONST&NBSP;CHAR&NBSP;*DST,&NBSP;CONST&NBSP;CHAR&NBSP;*SRC) {assert (DST); assert (SRC); const char *pdst = dst;const char *psrc = src;char *right= NULL;while (*DST) { while (*PDST&NBSP;==&NBSP;*PSRC) {if (*pdst== ') return right= (char *) dst;else{pdst+ +;p src++;}} if (*psrc == ') right = (char *) dst;pdst = ++dst;psrc = SRC;} Return right;} Int main () {char arr1[50] = { 0 };char arr2[40] = { 0 }; CHAR&NBSP;*PLACE&NBSP;=&NBSP;NULL;SCANF ("%s%s", ARR1,&NBSP;ARR2);p lace = my_strrstr (ARR1,&NBSP;ARR2); printf ("% #p \ n", place); System ("pause"); return 0;}
This article is from the "11132019" blog, please be sure to keep this source http://11142019.blog.51cto.com/11132019/1770998
Realization of STRCHR, STRRCHR and Strrstr