# Converting fixed length string to char and float

**URL:** <https://forum.arduino.cc/t/converting-fixed-length-string-to-char-and-float/1382552>\
**Category:** Programming\
**Created:** [May 19, 2025, 4:21am UTC](https://forum.arduino.cc/t/converting-fixed-length-string-to-char-and-float/1382552 "2025-05-19T04:21:53Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [May 19, 2025, 7:38am UTC](https://forum.arduino.cc/t/converting-fixed-length-string-to-char-and-float/1382552/6 "2025-05-19T07:38:21Z")

</div>

As discussed previously, the way your receive the data is not correct.

You need to rewrite that part and the best way is to handle the data as it comes.

You first need to sync with the start of a frame, so you need to listen to the first terminator CR LF (as you don't know if the first byte you get is really the first byte of the payload, you might have missed some) ➜ so ignore the first incoming bytes until you identify the CR LF. Then you are in sync and you receive the payload, check it's the right length when you get the next CR LF and then add a trailing null char in the buffer. Only then you can call sscanf() to extract the data from your buffer.

second guessing the timing of an asynchronous protocol is a recipe for failure...

You might benefit from studying state machines. Here is a small introduction to the topic: [Yet another Finite State Machine introduction](https://forum.arduino.cc/t/yet-another-finite-state-machine-introduction/1198997)

---

_[View the full topic](https://forum.arduino.cc/t/converting-fixed-length-string-to-char-and-float/1382552)._
