2 Replies Latest reply on Jul 28, 2018 12:46 PM by jeremy_3270776

    sprintf inconsistency or setup issue?

    jeremy_3270776

      Hello!  I actually have kind of a weird problem . . . So I have two different programs (one an example program, one that's running essentially the same code with some additional functionality) and I'm trying to run the same line of code with the same input values but I'm getting different results, which is a bit concerning.  Below is the line of code:

       

      uint8 lenstrg;

      char dispbuff[8];

      float dutycalc;

       

      lenstrg = sprintf( dispbuff, "%6.2f", dutycycle ); 

       

      Pretty straight forward, trying to take a float stored in dutycalc and turn it into a char array for the LCD.

       

      On a working program, my data buffer comes out correctly.  Assuming a calculated duty cycle of 50, I get the following:

       

      dispbuff    [8]    0x1FFF81CC (All)    char [8]

      0    32 ' '    0x1FFF81CC (All)    char

      1    53 '5'    0x1FFF81CD (All)    char

      2    48 '0'    0x1FFF81CE (All)    char

      3    46 '.'    0x1FFF81CF (All)    char

      4    48 '0'    0x1FFF81D0 (All)    char

      5    48 '0'    0x1FFF81D1 (All)    char

      6    0 '\000'    0x1FFF81D2 (All)    char

      7    0 '\000'    0x1FFF81D3 (All)    char

       

       

      On a non working program (same line of code, same duty cycle value of 50), I get the following:

       

      dispbuff    [8]    0x1FFF81E8 (All)    char [8]

      0    32 ' '    0x1FFF81E8 (All)    char

      1    0 '\000'    0x1FFF81E9 (All)    char

      2    128 '\200'    0x1FFF81EA (All)    char

      3    46 '.'    0x1FFF81EB (All)    char

      4    0 '\000'    0x1FFF81EC (All)    char

      5    32 ' '    0x1FFF81ED (All)    char

      6    0 '\000'    0x1FFF81EE (All)    char

      7    0 '\000'    0x1FFF81EF (All)    char

       

      I honestly have no idea why the same code can act differently on two different projects. I'm going to attach my "non-working" project here for anyone who wants to take a look at it (no idea if there's a simple explanation or if there's some sort of conversion library I should've added that would make this work correctly).  Any help you can give me would be greatly appreciated!  Thanks!