sprint or how to create a string

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

sprint or how to create a string

Post by stefan.erni »

Hi Ben
I need to create a string what is always 2char long. I need to show time on a Display. I wrote a text to Display macro.

it should be like this

sprintf(FCV_TEXT2DISPLAY," %x", 15); // result "15"

sprintf(FCV_TEXT2DISPLAY," %x", 2); // result "02"

But I just cachet a lot of errors.....

Can You help me to use printf or sprintf.....

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: sprint or how to create a string

Post by Benj »

Hello,

It looks like your using Flowcode from your variable names.

I would do this and this will then simulate and compile to hardware.

Code: Select all

Text2Display = ToString$( Number )
If (Number < 10)
  Text2Display  = "0" + Text2Display 
sprintf is a very large function used a lot on computers as it is very powerful but due to its power it's a very large function. Embedded compilers may not support it out the box. Some do but probably not all.

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: sprint or how to create a string

Post by stefan.erni »

If I put the code in "C-Code" ==> Error with Tostring$

If I put the code in "Calculation" ==> Error with IF

What if I put the code in simulate?

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: sprint or how to create a string

Post by stefan.erni »

Hi Ben

Ok I solved it...

Can I show text in the simulation on 100x32 pixel Display?

Post Reply