#include <stdio.h>//string Length (version one)//using a character array to implement int mystrlen1 (char s[]) {int len = 0;while (S[len]! = ')} {len++;} return Len;} String length (version two)//with character pointer implementation int Mystrlen2 (char *s) {int len = 0;while (*s! = ')} {len++;s++;} return Len;} int main () {char str[] = "Hello"; int n = mystrlen1 (str);p rintf ("%d\n", n), int m = mystrlen2 (str);p rintf ("%d\n", m); return 0;}
#include <stdio.h >//string copy (version one)//using an array to implement void Mystrcpy1 (char S[],char t[]) {int i=0;while ((s[i]=t[i])! = ' + ')//assignment First, Compares whether the string terminator {i++;}} Copy of string (version two)//use pointer to implement void Mystrcpy2 (char *s,char *t) {while ((*s = *t)! = ' + ') {s++;t++;}} Copy of string (version three)//using pointers for void mystrcpy (char *s, char *t) {while (*s++ = *t++); C Non-0 means logic is true, so do not compare with ' \ '} int main () {char a[] = "Hello", char b[100],c[100];mystrcpy1 (b,a);p rintf ("%s\n", b); Mystrcpy2 (c,a);p rintf ("%s\n", c); return 0;}
Library functions that implement C-string manipulation