在C语言中,printf和scanf函数使用的数据类型BYTE、WORD和DWORD的最合适格式说明符是什么?
我很难在控制台上显示BPB字段的值。
例如,如果我试图使用“%lu”显示BPB_BytsPerSec,就会得到不寻常的数字。。

printf("Bytes per Sector: %lu", b->BPB_BytsPerSec);

我得到的值是514,我相信这是错误的解释请建议出去的路谢谢。
(我通过MinGW在64位窗口上使用gcc 5.1)
以下是我们正在讨论的结构:
/* BPB Structure Collected from internet */
struct BPB_FAT32 {
  BYTE  BS_jmpBoot[3];      // 0
  BYTE  BS_OEMName[8];      // 3
  WORD  BPB_BytsPerSec;     // 11
  BYTE  BPB_SecPerClus;     // 13
  WORD  BPB_ResvdSecCnt;    // 14
  BYTE  BPB_NumFATs;        // 16
  WORD  BPB_RootEntCnt;     // 17
  WORD  BPB_TotSec16;       // 19
  BYTE  BPB_Media;          // 21
  WORD  BPB_FATSz16;        // 22
  WORD  BPB_SecPerTrk;      // 24
  WORD  BPB_NumHeads;       // 26
  DWORD BPB_HiddSec;        // 28
  DWORD BPB_TotSec32;       // 32
  DWORD BPB_FATSz32;        // 36
  WORD  BPB_ExtFlags;       // 40
  WORD  BPB_FSVer;          // 42
  DWORD BPB_RootClus;       // 44
  WORD  BPB_FSInfo;         // 48
  WORD  BPB_BkBootSec;      // 50
  BYTE  BPB_Reserved[12];   // 52
  BYTE BS_DrvNum;           // 64
  BYTE BS_Reserved1;        // 65
  BYTE BS_BootSig;          // 66
  DWORD BS_VolID;           // 67
  BYTE BS_VolLab[11];       // 71
  BYTE BS_FilSysType[8];    // 82
};

这就是我试图显示这些值的函数。。
void DisplayBlock(struct BPB_FAT32* b){

    printf("\n\n\t1.  Jump to boot code..........: 0x%02x%02x%02x",b->BS_jmpBoot[0],b->BS_jmpBoot[1],b->BS_jmpBoot[2]);
    printf("\n\n\t2.  OEM name & version.........: "); for(int i=0; i<8;i++) printf("%c",(char)b->BS_OEMName[i]);
    printf("\n\n\t3.  Bytes per Sector...........: %u",b->BPB_BytsPerSec);      // WORD
    printf("\n\n\t4.  Sectors per Cluster........: %lu", b->BPB_SecPerClus);    // BYTE
    printf("\n\n\t5.  Reserved Sectors Count.....: %lu", b->BPB_ResvdSecCnt);   // WORD
    printf("\n\n\t6.  Number of FAT32 tables.....: %u", b->BPB_NumFATs);        // BYTE
    printf("\n\n\t7.  Number of Root Entries.....: %lu", b->BPB_RootEntCnt);    // WORD
    printf("\n\n\t8.  Total Sectors 16bits.......: %lu",b->BPB_TotSec16);       // WORD
    printf("\n\n\t9.  Media Descriptor...........: %lu",b->BPB_Media);          // BYTE   0xF8 is the standard value for fixed media
    printf("\n\n\t10. Size According to FAT16....: %lu",b->BPB_FATSz16);        // WORD
    printf("\n\n\t11. Number of Sector per Track.: %lu",b->BPB_SecPerTrk);      // WORD
    printf("\n\n\t12. Number of Heads............: %lu",b->BPB_NumHeads);       // WORD
    printf("\n\n\t13. Number of Hidden Sectors...: %lu", b->BPB_HiddSec);       // DWORD
    printf("\n\n\t14. Total Sectors 32bits.......: %lu", b->BPB_TotSec32);      // DWORD
    /* FAT32 Specific Fields Starting offset:36 */
    printf("\n\n\t15. Size According to FAT32....: %lu", b->BPB_FATSz32);       // DWORD
    //printf("\n\n\t16. Extended Flags............: %u",b->BPB_ExtFlags);       // WORD  Usually 0.
    printf("\n\n\t17. File System Version........: %lu", b->BPB_FSVer);         // WORD         Must be 0:0
    printf("\n\n\t18. Root Cluster Number........: %lu",b->BPB_RootClus);       // DWORD        Usually 2
    printf("\n\n\t19. File System Information....: %lu",b->BPB_FSInfo);         // WORD
    printf("\n\n\t20. Backup Boot Sector.........: %lu",b->BPB_BkBootSec);      // WORD         Recomended 6
    //  BYTE  BPB_Reserved[12]
    /* Remaining common fields FAT12/FAT16 BPB*/
    printf("\n\n\t21. Drive Number...............: %u",b->BS_DrvNum);           // BYTE
    //  BYTE BS_Reserved1;      /* 65 reserved          */
    printf("\n\n\t22. Boot Signature.............: %u",b->BS_BootSig);          // BYTE
    printf("\n\n\t23. Volume ID..................: %lu",b->BS_VolID);           // DWORD
    printf("\n\n\t24. Volume Lable...............: %s",b->BS_VolLab); //for(int i=0;i<11;i++) printf("%c",b->BS_VolLab[i]);     // BYTE [11]
    printf("\n\n\t25. File System Type...........: "); for(int i=0;i<8;i++) printf("%c",b->BS_FilSysType[i]);  // BYTE [8]
}

下面是不满意的结果:
c - c语言中数据类型BYTE,WORD和DWORD的格式说明符?-LMLPHP

最佳答案

typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned long DWORD;
typedef unsigned long long QWORD;

09-30 19:28