2

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! – Nib Jun 20 '14 at 16:13
2

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.

  • Thank you! That was the tip I needed. – user1407 Jun 20 '14 at 18:48
3

If you use printf(" ") and printf("#") they will print one after another, when you need to go to the next line, just printf("\n")

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .