去哪网 2014.9.25 笔试题
#include <stdio.h>#include <stdlib.h>#include <string.h>char *overlay_fun(char *str, char *overlay, int start, int end){ char *copy = malloc(strlen(str)*sizeof(char)); int i = 0; int j = 0; if(strlen(str) == 0) return NULL; if(start < 0) start = 0; if(end < 0) end = 0; if(start > end) { int tmp; tmp = start; start = end; end = tmp; } if(start > strlen(str)) start = strlen(str); if(end > strlen(str)) end = strlen(str);for(i = 0; i < start; i++) { copy[i] = str[i]; } copy[i] = '\0'; while(overlay[j] != '\0') { copy[i] = overlay[j]; j++; i++; } while(str[end] != '\0') { copy[i] = str[end]; end++; i++; } str = copy; return copy;}