|
From: Noorez K. <coo...@ho...> - 2004-05-24 00:31:45
|
Help me with the problems with the program. It's sort of like an easy
dos-prompt.
1)The chdir function doesn't work
2)When you start a program, the program name stays on the blue banner at the
top of the window, even when the program as ended.
#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];
cout << "\nEnter the name of the drive you want to go to: ";
cin >> drv;
cin.ignore();
strcat(drv,":");
chdir(drv); /*chdir function that doesn't work*/
cout << "Now in drive " << drv << "\\" << endl;
cout << "You may type in commands" << endl;
system("pause");
strcat(drv,"\\>");
char coms[123];
while(1)
{
cout << drv;
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
}
_________________________________________________________________
STOP MORE SPAM with the MSN Premium and get 2 months FREE*
http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines
|