Author Topic: C printf multiple dashes  (Read 5493 times)

0 Members and 1 Guest are viewing this topic.

Offline arixroboticsTopic starter

  • Full Member
  • ***
  • Posts: 119
  • Helpful? 3
    • TalasTronics WCIT KL2008 Fund Raising
C printf multiple dashes
« 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.

Offline chelmi

  • Supreme Robot
  • *****
  • Posts: 496
  • Helpful? 15
    • Current projects
Re: C printf multiple dashes
« Reply #1 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("-");

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: C printf multiple dashes
« Reply #2 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.


Offline arixroboticsTopic starter

  • Full Member
  • ***
  • Posts: 119
  • Helpful? 3
    • TalasTronics WCIT KL2008 Fund Raising
Re: C printf multiple dashes
« Reply #3 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.

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: C printf multiple dashes
« Reply #4 on: October 20, 2009, 02:12:20 PM »
Yep, you can do that in Python.

 


Get Your Ad Here