|
From: Noorez K. <coo...@ho...> - 2004-02-13 23:35:03
|
The cin.getline() function in my loop skips the first time around. I marked
it with a comment
#include <iostream>
#include <cstdlib>
#include <direct.h>
using namespace std;
int system(bool cls);
int main()
{
cout << "Easy to use dos-prompt!" << endl;
cout << "\nTo switch dirves use this: drvswitch\n" << endl;
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;
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;
strcat(drv,":");
chdir(drv);
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); //this is skipped the first time around
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
}
_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE*
http://join.msn.com/?page=dept/bcomm&pgmarket=en-ca&RU=http%3a%2f%2fjoin.msn.com%2f%3fpage%3dmisc%2fspecialoffers%26pgmarket%3den-ca
|