10 char* inside_out (char* string
)
12 int length
= strlen(string
);
13 int center
= is_even(length
);
14 char* result
= calloc(sizeof(char), length
+ 1); // for NUL
15 int half
= (length
/ 2) - 1; // account for 0-index
17 for (int i
= 0; i
< length
; i
++)
20 result
[i
] = string
[0];
22 else if (center
&& (i
== (half
+ 1)))
23 result
[i
] = string
[half
+ 1];
25 else if (i
== (half
+ 1 + center
))
26 result
[i
] = string
[length
- 1];
29 result
[i
] = string
[i
+ 1];
32 result
[i
] = string
[i
- 1];
39 char* generate_square(char* string
)
41 int length
= strlen(string
);
42 // The size is for the square, the newlines and the NUL-term
43 int result_size
= (length
* length
) + length
;
44 char* result
= calloc(sizeof(char), result_size
);
46 char* current
= string
;
49 for (index
= 0; index
< (result_size
/ 2); index
++)
54 current
= inside_out(current
);
60 result
[index
] = current
[count
];
65 count
= (result_size
/ 2) - 1;
66 for (index
= (result_size
/ 2) - 1; index
< result_size
; index
++)
68 // printf("\nprocessing half...\n");
69 result
[index
] = result
[count
];