10 char* inside_out (char* string)
12 int length = strlen(string);
13 char left_edge = string[0];
14 char right_edge = string[length - 1]; // account for 0-index
23 if (is_even(length) != 0)
26 int half = (length / 2) - 1; // see above
28 left_cent = string[half];
29 right_cent = string[half + 1 + center];
31 result = calloc(sizeof(char), length + 1);
32 memcpy(result, string, (size_t) length);
34 result[0] = left_cent;
35 result[length - 1] = right_cent; // see above
36 result[half] = left_edge;
37 result[half + 1 + center] = right_edge;
42 char* generate_square(char* string)
44 int length = strlen(string);
45 // The size is for the square, the newlines and the NUL-term
46 char* result = calloc(sizeof(char), (length * length) + length);
48 char* current = string;
49 int newline_index = length + 1;
50 for (int index = 0; index < length; index++)
52 strcat(result, current);
53 result[newline_index - 1] = '\n';
54 newline_index += newline_index;
55 current = inside_out(current);
58 result[(length * length) + length - 1] = '\0';