|
From: Noorez K. <coo...@ho...> - 2004-09-03 17:31:29
|
I am getting some very strange results with my program. The first error is
that the input on the marked line, shows up on the next input line but has
not been entered. I used getch() to fix that but what went wrong?
Next error. If I enter 'y' for the auto clear screen then the marked input
line acts as if there was an input on each round of the main loop. If the
answer was 'n' it only skips once.
I tried debugging but still nothing...
#include <iostream>
#include <cstdlib>
#include <direct.h>
#include <string>
#include <myfs.h>
#include <conio.h>
using namespace std;
using namespace myf;
int sYstem(bool clrs);
int main()
{
console_init();
cursor_position(15,10);
text_color(cGreen,cBlack);
cout << "WELCOME TO EASY TO USE DOS-PROMPT\n";
wait();
cls();
cout << "Easy to use dos-prompt!" << endl;
cout << "\nTo quit you can use any one of the following commands: " <<
endl
<< "quit, bye, exit" << endl << endl;
char ask;
do
{
cout << "Would you like to enter the system? [Y\\N] ";
text_color(cRed,cBlack);
ask = getche();
cout << endl;
text_color(cGreen, cBlack);
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 clrs;
bool cLrs = FALSE;
text_color(cRed,cBlack);
clrs=getche(); //the character entered hear...
cout << endl;
text_color(cGreen,cBlack);
if(clrs == 'y' || clrs == 'Y')
{
cLrs = TRUE;
}
else if(clrs == 'n' || clrs == 'N')
{
cLrs = FALSE;
}
else
{
cout << "What...";
cout << "Default is set. No Clear Screen!\n";
cLrs = FALSE;
}
//return to main test
sYstem(cLrs);
wait();
return 0;
}
else if(ask == 'n' || ask == 'N')
{
cout << "Bye!" << endl;
wait();
cls();
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 clrs)
{
char* drv = new char;
cout << "\nEnter the name of the drive you want to go to: ";
text_color(cRed,cBlack);
cin.getline(drv,123); //comes out hear but enter key not pushed.
text_color(cGreen,cBlack);
strcat(drv,":\\");
chdir(drv);
cout << "Now in drive " << drv << endl;
cout << "You may type in commands" << endl;
wait();
cout << '\n';
strcat(drv,">");
char* coms;
while(1)
{
coms = new char;
if(coms == NULL)
{
cout << "No memory\n";
wait();
exit(1);
return 0;
}
cout << drv;
text_color(cRed,cBlack);
cin.getline(coms,124); //line is skipped if clear screen answer is y and
goes back to the top of the main loop.
text_color(cGreen,cBlack);
int comLen = strlen(coms);
if(coms[comLen-1]== ':')
{
delete drv;
drv = new char;
drv = coms;
chdir(coms);
strcat(drv,"\\>");
delete coms;
}
if( strcmp(coms,"exit")==0 || strcmp(coms,"bye")==0 ||
strcmp(coms,"quit")==0 )
{
if(clrs == TRUE)
{
cls();
}
return 0;
}
system(coms);
delete coms;
if(clrs == TRUE)
{
wait();
cls();
}
cout << endl;
}//while
}//end system def
_________________________________________________________________
Scan and help eliminate destructive viruses from your inbound and outbound
e-mail and attachments.
http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines
Start enjoying all the benefits of MSN® Premium right now and get the
first two months FREE*.
|