Realization of STRCHR, STRRCHR and Strrstr

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.