3

I've watched all the videos for pset1 and I cannot figure out how to make the space or indention print out more than once. Can anybody tell me where I'm supposed to find that kind of information? or just how to do it?

2 Answers 2

4

Investigate loops. Here's the Loops Short: http://www.youtube.com/watch?v=HHmiHx7GGLE

Also, watch Week 2 Monday's lecture for more insights.

for (int i = 0; i < 5; i++)
{
    printf("Hi! ");
}

The output of this is:

Hi! Hi! Hi! Hi! Hi!

Brenda.

1
  • ok. Thanks that was helpful. :D
    – user1267
    Commented Jun 13, 2014 at 3:32
1

This may not be the best way, but a simple way to repeat the characters can be done like this (as this answer suggests)

Short answer - yes, long answer: not how you want it.

You can use the %* form of printf, which accepts a variable width. And, if you use '0' as your value to print, combined with the right-aligned text that's zero padded on the left..

printf("%0*d\n", 20, 0); 

produces:

00000000000000000000

It does have some limitations, and honestly, I have no ides how it works, but I did manage to execute mario with it.

1
  • This is interesting, and I didn't know this before, but I honestly think that loops are the more understandable way to solve this.
    – ChiCubed
    Commented Jul 21, 2014 at 4:18

You must log in to answer this question.

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