2012-05-14 40 views
0
char *pStrBuffer; 

    unsigned char data; 
    unsigned int Address; 

    /* pStrBuffer reading from a file data in file of the form 
    WriteByte(0xDE04,0x20) 
    WriteByte(0xFE08,0x50) .... 

    */ 
    /* in a loop */ 
    sscanf(pStrBuffer,"%x%x",&Address,&data); 

編譯errror是GNU GCC 4.5在Windows XP 但是數值讀取的地址是0xDE00代替0xDE04?爲什麼是這樣,雖然數據的值被正確讀取。 我也嘗試分別使用%lx和%hx,但沒有用Çsscanf的在讀32位整數

回答

3

要讀取單個無符號字節,請使用%hhx修飾符。 %hx用於unsigned short,%x用於unsigned int,%lx用於unsigned long,而%llx用於無符號長整數。