sscanf doesn´t work right

Discussion in 'Programmer's Corner' started by kubeek, Mar 26, 2012.

  1. kubeek

    Thread Starter AAC Fanatic!

    Sep 20, 2005
    4,669
    804
    Hi,

    I´m trying to match some commands with sscanf.
    Code ( (Unknown Language)):
    1. char i, c,d,e;
    2.     i=sscanf("SET S 6 H ", "SET S%d H %d",&c,&d);
    3.      printf("scan %d: %d %d",i,c,d);
    responds "scan 1: 6 0"
    so it doesn´t parse the second number. however when I add the expected number to the input, the first number becomes zero.
    Any clues?


    Code ( (Unknown Language)):
    1. char i, c,d,e;
    2.     i=sscanf("SET S 6 H 4", "SET S%d H %d",&c,&d);
    3.      printf("scan %d: %d %d",i,c,d);
    responds "scan 2: 0 4"
     
  2. kubeek

    Thread Starter AAC Fanatic!

    Sep 20, 2005
    4,669
    804
    solved :)

    When compiler issues warnings, correct them. It said that &c should be int but is char which I ignored, so the high byte of that int overwrote the other variable.
     
Loading...