The 'sscanf' mistake

sscanf(buffer, "%d", &var1_1byte);

in the above case, var1_1byte is uint8_t (ie 1 byte char variable).
the "%d" in sscanf resulted to writing of multiple bytes (notice that '%d' is for 'int') which inturn cleared the adjacent bytes of ram at address &var1_1byte.

thus, var1_1byte, var2_1byte got modified. checking the .map file i confirmed the error and realized the mistake.

i used '%d' instead of '%c' so that ascii value in buffer is converted to integer (actually wanted to convert to hex).

Ignorant. (Sic).

luckily i could trace the error in not more than 5 minutes. a newbie may have consumed more time hence thought of bringing to the notice of others.

Parents
  • note:
    var1_1byte was at ram address -

    var1_1byte - 0x1000042c
    random_var - 0x1000042d
    var2_1byte - 0x1000042e

    the address can be checked by reading *.map file.

    ...ascii value in buffer is converted to integer (actually wanted to convert to hex)
    hex or integer is of less concern as the value will always be less than 9.

Reply
  • note:
    var1_1byte was at ram address -

    var1_1byte - 0x1000042c
    random_var - 0x1000042d
    var2_1byte - 0x1000042e

    the address can be checked by reading *.map file.

    ...ascii value in buffer is converted to integer (actually wanted to convert to hex)
    hex or integer is of less concern as the value will always be less than 9.

Children
More questions in this forum