Self-designed to achieve strlen,strcat,strcpy,strcmp.
int my_strlen (char *a) {int count=0;while (*a) {a++;count++;} Return count;} Char* my_strcat (char *a,char *b) {char *c;c=a;while (*a) {a++;} while (*b) {*a++=*b++;} Return c;} char* my_strcpy (char *c,char *b) {char *d;d=c;while (*b) {*c++=*b++;} Return d;} INT MY_STRCMP (char* a,char* b) {while ((*a!=0) && (*b!=0)) {a++;b++;} if (*a==0) return -1;else if (*b==0) return 1;elsereturn 0;} Int main () {int strlen,strcmp;char *p1,*p2;char arr1[20]= "Lalalalala"; char arr2[]= " huhuhu "; char arr3[20]=" 0 "; Strlen=my_strlen (arr1); printf ("%d\n ", strlen);p 1 = My_strcat (ARR1,ARR2); while (*P1) {printf ("%c", *p1++);} printf ("\ n");p 2=my_strcpy (ARR3,ARR2), while (*P2) {printf ("%c", *p2++);} printf ("\ n"); strcmp=my_strcmp (ARR1,ARR2);p rintf ("%d\n", strcmp); return 0;}
This article is from the "sunshine225" blog, make sure to keep this source http://10707460.blog.51cto.com/10697460/1754038
The realization of STRLEN,STRCAT,STRCPY,STRCMP