Timeline for Weird formatting behavior with sprintf function
Current License: CC BY-SA 3.0
10 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jan 28, 2017 at 13:37 | comment | added | jfpoilpret |
As mentioned by @jot your x is 4 bytes but sprintf expects it to be 2 bytes because you used %d in the format string. If you want to keep x as a long , then replace the first %d with %ld and that should fix it; otherwise declar x as int . Please accept @jot answer if that fixes your problem.
|
|
Jan 25, 2017 at 14:45 | comment | added | Jonathan Anctil | @jfpoilpret that don't work | |
Jan 25, 2017 at 7:37 | comment | added | jfpoilpret |
Have you tried replacing \r with \r\n at the end of your strings? it is possible that the serial console on your computer uses \r to return to the beginning of the line without going to a new line, then the latest content will override the previous one.
|
|
Jan 24, 2017 at 16:35 | answer | added | Jot | timeline score: 2 | |
Jan 24, 2017 at 15:08 | comment | added | Majenko | An array of ints if you really must store it. However, unless you have a requirement to do a block of high speed sampling followed by sending then don't bother storing - just write the values out as you sample them. You're not making the sending any faster by storing them, and that is by far the slowest operation. | |
Jan 24, 2017 at 15:05 | comment | added | Jonathan Anctil | What are you proposing for storing the data instead of string type? | |
Jan 24, 2017 at 15:01 | comment | added | Majenko | Serial is way slower than your acquisition. It depends if you want a block of data followed by a delay while it sends, or a smooth sending of values over time. Either way using strings to store the data isn't good - it's a huge waste. | |
Jan 24, 2017 at 14:59 | comment | added | Jonathan Anctil | I was just using sprintf to format data instead of using concat or «+», it seems more efficient to me. But hey, I'm open to improvement. My C is far far beyond me! Is this a best practice to do multiple acquisitions before sending it on the Serial or I can send it on each iteration? | |
Jan 24, 2017 at 14:52 | comment | added | Majenko | Why are you even using sprintf? What's wrong with just printing the values direct to serial? | |
Jan 24, 2017 at 14:33 | history | asked | Jonathan Anctil | CC BY-SA 3.0 |