2013-08-07 40 views
2

我写了一个小程序,将搜索我的电脑中的所有逻辑驱动器,然后打印它们。但不同的wirh我的预期,它不显示它们..这里是我的代码示例逻辑驱动器字母不显示

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 "); 
} 
+2

你调试了你的代码来确定哪里出了问题吗? –

+0

是的,我did..and没有什么是错误的根据我的代码调试器 – user2660085

+0

什么是输出?最新错误? –

回答

1

您的printf语句已损坏。使用此:

printf("%s ", szDrive); 

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

+0

是的,它工作..谢谢你 – user2660085