Several functions of String

zhaozj2021-02-16  92

INT STRLEN (Const Char * Str) {Const Char * SC;

FOR (sc = str; * sc! = '/ 0'; sc);

Return SC - Str;}

Char * strtrim (char * s) {char * pdst = s; while (1) {if (* pdst == '' || * PDST == '/ t' || * pdst == '/ n') { PDST ;} else {Break;}} char * p = pdst; while (* p) {p ;} p -; while (1) {if (* p == '|| * p ==' / t '|| * p ==' / n ') {p -;} else {breaf;}} * (p 1) =' / 0 '; return pdst;}

Char * strcat (char * DST, const char * src) {char * ptemp = dst;

While (* ptemp) PTEMP ; while (* Ptemp = * src );

Return dst;}

INT strcmp (const char * dst, const char * src) {int RET = 0; while (! (r = * dst - * src) && * dst) { src; Dst;}

IF (RET <0) RET = -1; ELSE RET = 1;

Return Ret;}

INT strcmp (const char * dst, const char * src, int count) {int RET = 0; while (! (r = * dst - * src) && * dst) {if (--count == 0) Break; src; DST;}

IF (RET <0) RET = -1; ELSE IF (RET> 0) RET = 1;

Return Ret;}

Char * STRCPY (CHAR * DST, Const Char * src) {char * ptemp = dst; while (* Ptemp = * src ); Return Dst;

Char * STRCPY (Char * DST, Const Char * src, int count) {char * ptemp = dst; while (count - && (* ptemp = * src ));

Return dst;}

Char * strchr (const char * s, int c) {for (; * s! = (char) C; s) IF (* s == '/ 0') return null; return (char *) s; }

Char * STRCHR (const char * s, int C) {const char * p = s strlen (s); do {if (* p == (char) c) return (char *) p;} while P> = s); return null;}

Char * strstr (const char * s1, const char * s2) {INT L1, L2;

L2 = Strlen (S2); if (! l2) return (char *) S1; L1 = Strlen (S1); while (l1> = L2) {L1 -; if (! STRCMP (S1, S2, L2)) Return (char *) S1; S1 ;} return null;}

转载请注明原文地址:https://www.9cbs.com/read-11398.html

New Post(0)