String length: #include <stdio.h> #include <stdlib.h> #include <assert.h>int my_strlen (const char *s) {assert (s); Int n=0;while (*s) {n++;s++;} Return n;} Int main () {char s[]= "Abcedf";p rintf ("%d", My_strlen (s)); system ("pause"); return 0;} String copy: #include <stdio.h> #include <stdlib.h> #include <assert.h>char *my_strcpy (char *s , const char *c) {assert (s); assert (c); Char *q=s;while (*s++=*c++) {;} Return q;} Int main () {char s[10]= "abced"; char c[]= "Aegdhj";p rintf ("%s", my_strcpy (S,c)); System ("pause"); return 0;} string comparison: #include <stdio.h> #include <stdlib.h> #include <assert.h>int my_strcmp (const Char *s,const char *c) {assert (s); assert (c); while (*s++==*c++) {if (*s) {return 0;}} Return *s-*c;} Int main () {char s[10]= "abced"; char c[]= "AEGDHJ"; if (my_strcmp (s,c)) printf ("s string large"); Else if ( my_strcmp==0) {printf ("as large as String");} elseprintf ("C string large"); System ("PausE "); return 0;} String connections: #include <stdio.h> #include <stdlib.h> #include <assert.h>char *my_strcat (char *s , const char *c) {assert (s); assert (c); Char *q=s;while (*s) {s++;} while (*s++=*c++) {;} Return q;} Int main () {char s[20]= "abced"; char c[]= "Aegdhj";p rintf ("%s", My_strcat (S,c)); System ("pause"); return 0;}
This article from "Liveyoung" blog, reproduced please contact the author!
Implementation of string manipulation functions