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
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.
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 ofprintf
, 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.
-
This is interesting, and I didn't know this before, but I honestly think that loops are the more understandable way to solve this.– ChiCubedCommented Jul 21, 2014 at 4:18