I am stuck at converting the integer input I get from the user into spaces/hashes. How to use this integer with my printf()
function to print spaces/hashes?
-
I highly recommend you use your own brains for that, otherwise, it destroys the whole purpose of a problem set!– NibCommented Jun 20, 2014 at 16:13
2 Answers
There are many ways to solve this problem(mario.c). I don't want to spoil your work by providing an exact answer, but for your question how you translate this "number" that I can printf into an actual number of spaces and hash signs, may be this could help.
If variable no_spaces
holds the number of spaces, then
int i;
for (i = 0 ; i <= height+1 ; ++i)
{
if (i <= no_spaces)
printf(" ");
else
printf("#");
}
Remember that this code is itself insufficient to solve the problem, you need an outer loop that changes the value of no_spaces
. Think of it. Good luck.
If you use printf(" ") and printf("#") they will print one after another, when you need to go to the next line, just printf("\n")