逻辑驱动器号不显示

时间:2013-08-07 10:21:00

标签: c++ c

我编写了一个小程序,它将在我的PC中搜索所有逻辑驱动器,然后打印它们。但与我的预期不同,它没有显示它们。这是我的代码示例

TCHAR szDrive[] = (" A:");    
DWORD drive = GetLogicalDrives();
printf("The bitmask of the logical drives in hex: %0X\n", drive);
printf("The bitmask of the logical drives in decimal: %d\n", drive);
if(drive == 0)
    printf("GetLogicalDrives() failed with failure code: %d\n", GetLastError());
else
{
    printf("This machine has the following logical drives:\n");
    while(drive)
    {
    // Use the bitwise AND, 1â€"available, 0-not available
    if(drive & 1)
        printf("%S ", (const char *)szDrive);
    // increment, check next drive
    ++szDrive[1];
    // shift the bitmask binary right
    drive >>= 1;
}
printf("\n ");
}  

1 个答案:

答案 0 :(得分:1)

您的printf声明已损坏。使用此:

printf("%s ", szDrive);

我猜您使用%S代替%s只是一个错字。

相关问题