Your lucky day.
Code:
/* main.cpp, Copy_Twice, Created by Great on 9/10/22. */
#include <stdio.h>
#include <stdlib.h>
#pragma mark - Interface
unsigned long array_length(const int *);
#pragma mark - Implementation
unsigned long array_length(const int *array) {
const int *a = array;
while (*a) {
++a;
}
return a - array;
}
int main(int argc, const char *argv[]) {
int nums[16] = {1, 2, 3, 0};
int *ans = 0;
int i = 0;
int n = 0;
int size = 0;
n = (signed int)array_length(nums);
size = 1 + n + n;
ans = (signed int *)malloc(sizeof(signed int) * size);
if (0 == ans) {
printf("Error: malloc()\n");
} else {
while ('\0' != nums[i]) { /* Copy array */
ans[i] = nums[i];
i = 1 + i;
}
i = 0; /* Reset i to 0 */
while ('\0' != nums[i]) { /* Copy array again */
ans[i + n] = nums[i]; /* {1, 2, 3} + {1, 2, 3} */
i = 1 + i;
}
ans[i + n] = 0; /* End array with null */
free(ans); /* malloc() -> free() */
ans = 0;
}
return 0;
}