Welcome the boards......n00b!!
J/K
>> bool *Drives[26]
This is an array of 26 pointers that point to type bool. What you want is an array of 26 bools: "bool Drives[26]"
>> *Drives = false, false (left off curleys)
If you want A: and B: to always be false, the use
> Drives[0] = false;
> Drives[1] = false;
>> if (_chdrive(c+1) != NULL)
You should compare with 0 instead of NULL. Or since _chdrive() returns -1 on failure, just check for that.
>> *Drives[c]
Get rid of the *
>> char(97+c)
Or char('A' + c)
Don't try to compress the format of you code either, just makes less readable.
Code:
void ExistingDrives(bool Drives[26])
{
int c = 2;
Drives[0] = false;
Drives[1] = false;
while (c < 26)
{
cout << endl << char('A' + c) << ":";
if (_chdrive(c+1) == -1)
{
Drives[c] = false;
cout << " doesn't exist";
}
else
{
Drives[c] = true;
cout << " exists";
}
c++;
}
}
Now what you should be using is GetLogicalDrives(). The method you are using will not work for drives that don't have any media. CD-ROM drives will not show up unless there is a CD in the drive.
GetLogicalDrives() returns of a bitmask where the first 26 bits indicate if the drive exists or not. If pointers are new to you then bit twiddling may be too. Give another post if you have any questions.
Code:
#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
DWORD mask = GetLogicalDrives();
if (mask == 0)
{
cerr << "GetLogicalDrives() failes, last error = "
<< GetLastError() << endl;
return 1;
}//if
for (int bit = 0; bit < 26; bit++)
{
cout << (char)('A' + bit) << ": ";
if (mask & (1 << bit))
cout << "exists" << endl;
else
cout << "doesn't exist" << endl;
}//for
return 0;
}//main
gg