sscanf input problems

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dissectcode
    New Member
    • Jul 2008
    • 66

    sscanf input problems

    Hello - Is there a problem with certain input types for scanf, out there? I have:

    Code:
    UINT16 code;
    UINT8 type;
    UINT16 mask;
    UINT8 format;
    
    sscanf("0x%2X, %d, 0x%2X, %d", code, type, mask, format);
    UINT16 is a short unsigned int, and UINT8 is a short unsigned char.

    I get a warning of different type formats and args. I tried putting the h in %2hX and a %c for the char's, and then my code wouldn't even compile....Is there some glitch with scanning smaller numbers?

    thanks!
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    I dont think there are issues with reading the variables using sscanf.
    why do u use 0x before every format spcifier....?
    Which compiler u are using?

    Raghu

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      When using a function from the scanf family in all cases you need to pass pointers to variables, not variables.

      Comment

      • Brosert
        New Member
        • Jul 2008
        • 57

        #4
        (
        Raghu,

        I would imagine because he is printing Hex numbers...
        It's common to see Hex numbers prefixed with "0x" to identify that they are in base 16 rather than base 10...

        0x32 (50) is easily distinguished from 32 (32)....

        )

        Comment

        • gpraghuram
          Recognized Expert Top Contributor
          • Mar 2007
          • 1275

          #5
          Originally posted by Brosert
          (
          Raghu,

          I would imagine because he is printing Hex numbers...
          It's common to see Hex numbers prefixed with "0x" to identify that they are in base 16 rather than base 10...

          0x32 (50) is easily distinguished from 32 (32)....

          )

          For printing its is Fine...
          But why he needs it when reading the data......

          Raghu

          Comment

          • dissectcode
            New Member
            • Jul 2008
            • 66

            #6
            Originally posted by gpraghuram
            I dont think there are issues with reading the variables using sscanf.
            why do u use 0x before every format spcifier....?
            Which compiler u are using?

            Raghu

            The 0x is there so we can read in hex. And I think we are using a homemade compiler..using make. thanks...

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by dissectcode
              The 0x is there so we can read in hex. And I think we are using a homemade compiler..using make. thanks...
              One little nitpick: a compiler doesn't use 'make'; it's the other way around and it
              doesn't say anything about the brew of the compiler. All those IDEs nowadays
              just obfuscate which things do what and what it's all about.

              kind regards,

              Jos

              Comment

              Working...