String replacement

xiaoxiao2021-03-05  24

#include #include #include #include char * strreplace (char * base, char * oldstr, char * newstr) {Int i = strlen Oldstr), J = Strlen (newstr), FIT = 0; char * TEMP = (Char *) Malloc (Strlen 1) * sizeof (char)), * p = base; char * TEMPB = (char) *) Malloc (Strlen Fit * (JI) 1) * SizeOf (CHAR)); IF (Strlen (Base)

IF (j> i) {structure (TEMPB, BASE); Base = Tempb;} P = base; while (* p) {IF (Strncmp (p, oldstr, i)) p ; else {structure (TEMP, P I); STRNCPY (P, Newstr, J); STRCPY (P J, Temp);}}}} (j> i) base = tempb; return base;} int main () {char base [] = "Hello Java Java java "; char oldstr [] =" java "; char newstr [] =" dephic "; Printf ("% s / n ", strreplace (base, oldstr, newstr)); getCh (); return 0;}

No release space will be replenished.

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

New Post(0)