The easiest way is to use memset().
Code:
char *make_spaces(int z)
{
static char spaces[1024]; // Or some other sufficiently large number
memset(spaces, ' ', z);
spaces[z] = '\0'; // Make sure you NUL-terminate the string.
return spaces;
}
Here's an example using a loop if you prefer that:
Code:
char *make_spaces(int z)
{
static char spaces[1024];
int i;
for(i = 0;i < z;++i)
spaces[i] = ' ';
spaces[z] = '\0';
return spaces;
}
And another example without the need for the i counter:
Code:
char *make_spaces(int z)
{
static char spaces[1024];
spaces[z] = '\0';
while(--z >= 0)
spaces[z] = ' ';
return spaces;
}