Society of Robots - Robot Forum

Software => Software => Topic started by: arixrobotics on October 16, 2009, 08:25:23 AM

Title: C printf multiple dashes
Post by: arixrobotics on October 16, 2009, 08:25:23 AM
Hi all,

Does any body know how to write a multiple copy of a character to an LCD using printf?

To further explain my question;
I want to write
Code: [Select]
printf("-", *3)so that the output is 3 dashes
Quote
---

Or if I write
Code: [Select]
printf("-", *14)so that the output is 14 dashes
Quote
--------------

But the arguments is wrong ie
Code: [Select]
printf("-", *3) doesn't work. Does anybody know what I should put instead?
Code: [Select]
printf("-", what to write here?)
Thanks.
Title: Re: C printf multiple dashes
Post by: chelmi on October 16, 2009, 09:20:07 AM
The only way to do this is to write a for loop

for(int i=0; i<3; i++) printf("-");
Title: Re: C printf multiple dashes
Post by: waltr on October 16, 2009, 09:47:54 AM
Yep, in C the for loop is how to do it.

You do need to look up the syntax for a printf statement to learn "what to write here?".
printf("-", what to write here?)

Another way is to create a string of 3 or more "-"'s and then output the string with the printf.

Title: Re: C printf multiple dashes
Post by: arixrobotics on October 19, 2009, 08:38:25 AM
Yup i guess its for loop then. I remembered doing it somewhere else before, but maybe that was in Python. Thanks.
Title: Re: C printf multiple dashes
Post by: waltr on October 20, 2009, 02:12:20 PM
Yep, you can do that in Python.