char * cpyCatch( char * str, const int index ){ if( index > 0 && index < Catch.index ) strnCpy( str, Catch.ptr[ index ], Catch.len[ index ] ); else *str = '\0'; return str; }
char * rplCatch( char * newStr, const char * rplStr, const int id ){ char *oNewStr = newStr; const char *last = Catch.ptr[ 0 ]; for( int index = 1, rpLen = strLen( rplStr ); index < Catch.index; index++ ) if( id == Catch.id[ index ] ){ if( last > Catch.ptr[index] ) last = Catch.ptr[index]; strnCpy( newStr, last, Catch.ptr[index] - last ); newStr += Catch.ptr[index] - last; strCpy( newStr, rplStr ); newStr += rpLen; last = Catch.ptr[index] + Catch.len[index]; } strnCpy( newStr, last, Catch.ptr[0] + Catch.len[0] - last ); return oNewStr; }
main(){ char *s0 = "abcd", *s1 = "efg", *s2 = "def", st[MAXLEN]; strCat(st, s0); strCat(st, s1); printf("New st is %s.\n", st); strnCpy(s1, st, 2); printf("%s\n", st); return 0; }