2013-08-07 42 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