2019 1-22
#include <stdio.h> static int string_length(const char*p); //void strcpy(char *p1, const char *p2); int strcmp(char *m1, char *m2); char *strcat(char *n1, char *n2, char *n3); int main() { char a[]="hello"; char b[]="helll"; char s[]=""; char *p2=a; char *p=b; int c; long int length; length=string_length(p2); printf("length:%ld\n", length); strcpy(p, p2); printf("%s\n", p); c=strcmp(a, b); printf("%d\n", c); strcat(a, b, s); printf("%s\n", s); return 0; } //输出字符串的字长 static int string_length(const char*p) { int length=0; while(*p++) length++; return length; } //复制 void strcpy(char *p1, const char *p2) { while((*p1=*p2)!='\0'){ *p2++; *p1++; } } //strcmp: int strcmp(char *m1, char *m2) { while(*m1==*m2){ if(*m1=='\0') return 0; else { *m1++; *m2++; } } return (*m1-*m2); } //strcat char *strcat(char *n1, char *n2, char *n3) { static int i=0; while(*n1!='\0'){ *(n3+i)=*n1; i++; *n1++; } do { *(n3+i)=*n2; i++; *n2++; }while(*n2!='\0'); }