用C语言复制字符串表面上很简单,实际很复杂。
读者可以自己写一下,与此程序对比一下,想一下为什么这样写。
char * Strcpy(char * dest, const char * source) { if(source < dest) { const char * p = source; while(*p++); if(dest < p) { dest += p - source; for(;;) { *--dest = *--p; if(p == source) return dest; } } } { char * result = dest; while(*(dest++) = *(source++)); return result; } }