2

我编写了一个小程序,它将搜索我 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 ");
}  
4

1 回答 1

1

您的 printf 语句已损坏。用这个:

printf("%s ", szDrive);

我猜你使用的%S而不是%s只是一个错字。

于 2013-08-07T10:28:01.873 回答