Simulation implementation of a large wave library function

Source: Internet
Author: User

#include <stdio.h> #include <assert.h>//pointer Streln//int my_strlen (CONST&NBSP;CHAR&NBSP;*SRC)//{// int count = 0;//while  (*src++)//count++;//return count;//}//array Strlen//int my_ Strlen (const char src[])//{//int count = 0;//while  (Src[count])//count++;// return count;//}//recursive Strlenint my_strlen (CONST&NBSP;CHAR&NBSP;*SRC) {if  ('  == *src ') Return 0;elsereturn my_strlen (++SRC)  + 1;} Char *my_strstr (CONST&NBSP;CHAR&NBSP;*DEST,&NBSP;CONST&NBSP;CHAR&NBSP;*SRC) {assert (dest); assert (SRC); char  *pdest = dest,*s1=NULL,*s2=NULL;if  (!*SRC) return dest;while  (*pdest) {s1 =  pdest;s2 = src;while  (*s1 && *s2 && ! ( *S1&NBSP;-&NBSP;*S2) s1++, s2++;if  (!*S2) return pdest;pdest++;} Return null;} char *my_strcpy (CHAR&NBSP;*DEST,CONST&NBSP;CHAR&NBSP;*SRC) {assert (dest); assert (SRC); const char *pdest = dest;while  (*SRC) {if  ('  == *dest ') return pdest;*dest ++ = *src++;} Return pdest;} Char *my_strcat (CHAR&NBSP;*DEST,&NBSP;CHAR&NBSP;*SRC) {assert (dest); assert (SRC); char *psrc =  src;while  (*SRC) src++;while  (*dest) *src++ = *dest++;*src =  ' + '; return &NBSP;PSRC;} INT&NBSP;MY_STRCMP (CONST&NBSP;CHAR&NBSP;*DEST,&NBSP;CONST&NBSP;CHAR&NBSP;*SRC) {assert (dest); assert (SRC); while   (*dest && *src && ! ( *src - *dest)) dest++,src++;return  (*src - *dest);} void *my_memcpy (Void *dest, const void *src,size_t len) {assert (dest); assert (SRC) ;char *pdest =  (char *) dest;char *psrc =  (char *) src;while  (len-- ) {*pdest = *psrc;pdest++, psrc++;} return  (char *) dest;} Void *my_memmove (void *dest, void *src, size_t cOunt) {assert (dest); assert (SRC);char *pdest =  (char *) dest;char *psrc =  ( char *) src;if  (pdest <= psrc | |  pdest >=  (Psrc+count)//Prevents dest of the head and SRC from the tail contact situation into the loop (judging need forward copy) {while  (count--) {*pdest  = *psrc;pdest++, psrc++;}} else//only Dest's head and SRC tail contact require reverse copy {pdest =  (char *) dest + count;psrc =  (char  *) src + count;while  (count--) {*pdest = *psrc;*pdest--,  *psrc--;}} return  (char *) dest;} Int main () {char arr[20] =  "123456789";char arr2[] =  "456"; char arr3[20 ] =  "000000000";char arr4[] =  "87654321";char arr5[] =  "123456889"; char arr6[20] = { 1, 2, 3, 4, 5 };char arr7[20] =  { 0 };p rintf ("len=%d,loc=%p\n",  my_strlen (arr), My_strstr (ARR,ARR2));p rintf ("%d\n",  my_ strcmp (arr5,&Nbsp;arr));p rintf (my_strcpy (Arr3, arr));p rintf ("\ n");p rintf (My_strcat (Arr4, arr));p rintf ("\ n"); My_ memcpy (arr7, arr6,20); My_memmove (arr7, arr6, 12); System ("pause"); return 0;}


Simulation implementation of a large wave library function

Related Article

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.