0
這個函數的目的是用它的迴文創建一個字符串concat。例如 abc - > abccba一個字符串及其迴文
這是我的代碼,結果仍然顯示原始字符串沒有任何變化。我爲字符串及其迴文保留了一些空格,但它仍然不起作用。
char *mirror(const char *str) {
char *result = malloc(2 * strlen(str) * sizeof(char));
int str_len = strlen(str);
for (int i = 0; i < str_len; ++i) {
result[i] = str[i];
}
for (int j = str_len; j < 2*str_len; ++j) {
result[j] = str[2*str_len-j];
}
return result;
}