This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP432P401R: IAR/MSP432P401R: snprintf make error

Part Number: MSP432P401R

Hi all,

Im have a problem with snprintf fucition, after call snprintf() to write string to buffer, it changed some my variable.

Berfore

After

Any help will be appreciated. Thank you!

lenbufferpasscode = 267

static char Bufferpasscodeesp[300+1] = {0};

lenbufferpasscode = snprintf(Bufferpasscodeesp,300,",\"Passcode\":[{\"Code\":%d,\"Time\":%d,\"Opt\": %d ,\"Nuser\":%d},{\"Code\":%d,\"Time\":%d,\"Opt\": %d ,\"Nuser\":%d},{\"Code\":%d,\"Time\":%d,\"Opt\": %d ,\"Nuser\":%d},{\"Code\":%d,\"Time\":%d,\"Opt\": %d ,\"Nuser\":%d},{\"Code\":%d,\"Time\":%d,\"Opt\": %d ,\"Nuser\":%d}]",
    Passcodenumber1.Codenumber,Passcodenumber1.Timenumber,Passcodenumber1.Optionnumber,Passcodenumber1.Usenumber,
    Passcodenumber2.Codenumber,Passcodenumber2.Timenumber,Passcodenumber2.Optionnumber,Passcodenumber2.Usenumber,
    Passcodenumber3.Codenumber,Passcodenumber3.Timenumber,Passcodenumber3.Optionnumber,Passcodenumber3.Usenumber,
    Passcodenumber4.Codenumber,Passcodenumber4.Timenumber,Passcodenumber4.Optionnumber,Passcodenumber4.Usenumber,
    Passcodenumber5.Codenumber,Passcodenumber5.Timenumber,Passcodenumber5.Optionnumber,Passcodenumber5.Usenumber); 

  • In the screen captures the lenbufferpasscode is 0 (before and after) but in the text of the post it says 267. Can you explain what is happening? Is the 267 expected but the snprintf is returning '0'?

    Have you looked into your SRAM usage and or tried using a smaller array size to see if the issue goes away?

    Chris
  • Hi Chris,

    I mean, after use snprintf fuction, some variable has been changed, the screen captures just show the change.

    The following code also changes the variable

    snprintf(BufferMinutesEnter,3,"%02d",ListUsersLatest[i].minutes);

    267 is the return value, it < 300, I think it is not an overflow buffer.

    I try replace the snprintf by another fuction. Do you have any comments?

    Phuong

  • No I do not have any comments. I would recommend inquiring with IAR support.

    Regards,
    Chris

**Attention** This is a public forum