1. 字符串拼接
void myStrCat(char* s1,char* s2,char** ret){ char* r; r=(char*)malloc(strlen(s1)+strlen(s2)+1); if(!r){ printf("memory allocate failure\n"); exit(1); } strcpy(r,s1); strcat(r,s2); *ret = r; //TODO be carefull free this memory }
2. 缓冲区拷贝
void bufCopy(char* p, int n){ int N; char* bufptr; char* buffer; buffer = (char*)malloc(sizeof(char)*N); while (n > 0){ int k, rem; if(bufptr == &buffer[N]){ //TODO flush buffer ; } rem = N - (bufptr - buffer); k = n > rem? rem: n; memcpy(bufptr,p,k); p += k; n -= k; } }