2012-05-14 39 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用于无符号长整数。