I want to use sprintf function to convert a float to string, here is part of the main.c code : (PIC24JF64GA004)

double VLine1Float; 
char LCDBuffer[4]; 
VLine1Float = 3.33;  

it is compiled with no errors, but when I run it, it gets stuck at the sprintf function and does nothing except executing interrupts routines.

The function work normally with unsigned integer to string conversion, with both %u and %x specifiers

I tried everything but it just doesn't work with float. I just want to add that I used it in the past with xc8 and it worked

Any one can help ?

  • 2
    \$\begingroup\$ I’m voting to close this question because it's a pure programming question with no microcontroller-specific or electronic-related aspects. It belongs on stackoverflow.com \$\endgroup\$
    – Lundin
    Feb 23 at 7:43
  • 1
    \$\begingroup\$ I wrote a short beginner FAQ regarding strings here: Common string handling pitfalls in C programming. Yours is bug #2 in the FAQ. \$\endgroup\$
    – Lundin
    Feb 23 at 7:44
  • \$\begingroup\$ A C string needs an extra NULL terminator byte on the end of the string, so your 4 character string needs a 5 byte array to hold it. \$\endgroup\$
    – brhans
    Feb 23 at 16:22

1 Answer 1


The array is not long enough to contain the string.


Not the answer you're looking for? Browse other questions tagged or ask your own question.