10 char* inside_out (char* string
)
12 int length
= strlen(string
);
13 int center
= is_even(length
);
14 char* result
= calloc(sizeof(char), length
+ 2); // for newline and
16 int half
= (length
/ 2) - 1; // account for 0-index
18 for (int i
= 0; i
< length
; i
++)
21 result
[i
] = string
[0];
23 else if (center
&& (i
== (half
+ 1)))
26 else if (i
== (half
+ 1 + center
))
27 result
[i
] = string
[length
- 1];
30 result
[i
] = string
[i
+ 1];
33 result
[i
] = string
[i
- 1];
36 result
[length
+ 1] = '\n';
41 char* generate_square(char* string
)
43 int length
= strlen(string
);
44 // The size is for the square, the newlines and the NUL-term
45 int result_size
= (length
* length
) + length
;
46 char* result
= calloc(sizeof(char), result_size
);
48 char* current
= string
;
49 for (int i
= 0; i
< length
; i
++)
51 strcat(result
, current
);
52 result
[(length
+ 1) * (i
+ 1)] = '\n';
53 current
= inside_out(current
);