First, let's take a look at the strlen function that we are often familiar with in our study.
Strlen 1: Pointer difference value returned
int My_strlen (const char *str) {char *pst = (char *) str; ASSERT (str); while (*STR) {str++; } return str-pst;}
STRLEN2: Recursive implementation
int my_strlent (const char *str) {assert (str); if (*STR) return 1+my_strlent (str+1); else return 0;}
Strlen3: Counter Control
int My_strleno (const char *str) {int count = 0; ASSERT (str); while (*str++) {count++; } return count;}
STRCMP's writing:
INT&NBSP;STRCMP (CONST&NBSP;CHAR&NBSP;*STR,&NBSP;CONST&NBSP;CHAR&NBSP;*DSTR) //judgment function, does not allow changing parameters y{ int ret = 0; //definition return value assert ((str != null) && (dstr != null)); //D Break while (! ( ret =* (unsigned char*) str - * ( unsigned char *) Dstr) && DSTR) //calculates the value of RET: o if?? The value of the string is &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&Nbsp; //the same as A0, greater than, less than a-1; { str++; //when judging the end of a string; Dstr++; } if (ret < 0) ret = -1; else if (ret > 0) ret = 1; return ret;}
strcpy:
#include <stdio.h> #include <assert.h>char *my_strcpy (char *dstr,char CONST&NBSP;*SSTR) { char *Astr = (char *) dstr; assert (dstr != null) && (sstr != null)); while ((*DSTR&NBSP;=&NBSP;*SSTR) != ' + ' ) { Dstr++; Sstr++; } return astr;}
Strcat:
Char *my_strcat (CHAR&NBSP;*DSTR,CHAR&NBSP;CONST&NBSP;*SSTR) { char *Astr = (char *) dstr; assert (dstr != null) && (Sstr != null)); while (' + ') &NBSP;!=&NBSP;*DSTR) dstr++; *dstr = ' '; dstr++; while (' != *sstr ') { *dstr++ = *Sstr++; } *Dstr = '; ' return astr;}
Well, this blog post is like this, and it's all about the string manipulation functions that we use, and then we all pay attention to the concise mode of assert and writing. Yes, that's it.
This article is from the "egg-left" blog, please be sure to keep this source http://memory73.blog.51cto.com/10530560/1696331
Strlen three ways to implement the strcmp,strcat,strcpy