There is no need to modify the all-spaces string as we can as well
print its end in order to output the desired number of spaces. This
allows to make the array variable const, along with "sz", which stores
the length of the string.
/* Print given number of spaces to curses window. */
static void add_spaces(WINDOW* win, unsigned int num)
{
- char space[] = " ";
- unsigned sz = sizeof(space) - 1; /* number of spaces */
+ const char space[] = " ";
+ const unsigned sz = sizeof(space) - 1; /* number of spaces */
while (num >= sz) {
waddstr(win, space);
}
if (num > 0) {
assert(num < sz);
- space[num] = '\0';
- waddstr(win, space);
+ waddstr(win, space + sz - num);
}
}