I need help with this program. It is sort of like a dos-prompt thing. When
you enter the name of your drive it will search for it but even if it
doesn't exist it will tell you that you are in the drive. Is there a
function that can test to see the existence of a drive.
#include <iostream>
#include <cstdlib>
#include <direct.h>
#include <string>
using namespace std;
int sYstem(bool cls);
int main()
{
cout << "Easy to use dos-prompt!" << endl;
cout << "\nTo switch dirves use this: drvswitch\n";
cout << "\nTo quit you can use any one of the following commands: \n"
<< "quit, bye, exit\n";
char ask;
do
{
cout << "\nWould you like to enter the system? [Y\\N] ";
cin >> ask;
if(ask == 'y' || ask == 'Y')
{//main if
cout << "\nYou can also have the program Clear Screen automaticly after
each command.\n";
cout << "Is this Ok [Y\\N] ";
char cls;
bool cLs = FALSE;
cin >> cls;
if(cls == 'y' || cls == 'Y')
{
cLs = TRUE;
}
else if(cls == 'n' || cls == 'N')
{
cLs = FALSE;
}
else
{
cout << "What...";
cout << "Default is set. No Clear Screen!\n";
cLs = FALSE;
}
//return to main test
sYstem(cLs);
system("pause");
return 0;
}
else if(ask == 'n' || ask == 'N')
{
cout << "Bye!" << endl;
system("pause");
return 0;
}
else
{
cout << "What....\n" << endl;
}
}while(ask != 'y' || ask != 'Y' || ask != 'n' || ask != 'N');
return 0;
}
//define the system function
int sYstem(bool cls)
{
drvswitch:
char drv[8];
char dr[8]={};
cout << "\nEnter the name of the drive you want to go to: ";
cin >> drv;
strcpy(dr,drv);
strcat(drv,":\\");
chdir(drv);
cout << "Now in drive " << dr << ":\\" << endl;
cout << "You may type in commands" << endl;
system("pause");
strcat(dr,":\\>");
char coms[123];
while(1)
{
cout << dr;
cin.sync();
cin.getline(coms,124);
if( strcmp(coms,"exit")==0 || strcmp(coms,"bye")==0 ||
strcmp(coms,"quit")==0 )
{
return 0;
}
if(strcmp(coms,"drvswitch")==0)
{
goto drvswitch;
}
system(coms);
if(cls == TRUE)
{
system("pause");
system("cls");
}
cout << endl;
}//while
}
_________________________________________________________________
Free yourself from those irritating pop-up ads with MSn Premium. Get 2months
FREE*
http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines
|