Another n00b with pointer problems!
This is the first program that I'm writing that uses pointers (and overall the second I'm writing in C++).
I want DrivesToDo (a 26-digit boolean) to be filled by ExistingDrives. Every bit stands for a drive letter, so DrivesToDo[2] will be TRUE if a C-partition exists. I'm doing some stuff wrong though I can't figure out what it is. It worked when I first wrote it without using pointers. The program is written in MSVC6.0 and I guess it won't compile under any other compiler. The errors I get are the following:
loc.cpp(9) : error C2664: 'ExistingDrives' : cannot convert parameter 1 from 'bool (*)[26]' to 'bool *[]'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
loc.cpp(16) : error C2059: syntax error : '{'
loc.cpp(16) : error C2143: syntax error : missing ';' before '{'
loc.cpp(16) : error C2143: syntax error : missing ';' before '}'
It's probably a very stupid error I made, but I'm so newbie-ish I just can't figure it out... Help would be appreciated! Here's the code:
Code:
#include <direct.h>
#include <iostream.h>
void ExistingDrives(bool *Drives[26]);
int main(void)
{ bool DrivesToDo[26];
ExistingDrives(&DrivesToDo);
return(0);
}
void ExistingDrives(bool *Drives[26])
{ int c=2;
*Drives = {false, false};
while (c < 26)
{ cout << endl << char(97+c) << ":";
if (_chdrive(c+1) != NULL) { *Drives[c] = false; cout << " doesn't exist"; }
else { *Drives[c] = true; cout << " exists"; }
c++;
}
}
Re: Another n00b with pointer problems!
Quote:
Originally posted by Bastaard
The program is written in MSVC6.0 ...
You're not making a DOS application. If you want it to work correctly and efficiently under any Win32 platform, then use the functions I've shown.
gg