Use printf("%*s", n, "") instead of allocating a string filled with spaces.
There is an obvious name collision with the popular file manager midnight commander.