|
From: Per W. <pw...@ia...> - 2004-09-03 18:46:07
|
So the reason you never give feedback to received answers - you never read
them...
Be _very_ careful about mixing FILE-based and stream-based input and/or
output to the _same_ stream, since the C library and the C++ stream
library have their own input/output buffer code. When mixing them, serious
problems with interaction may/will follow. Regularly flushing the streams
may help the problem, but the best solution is to not mix the two
input/output methods!
/Per W
On Fri, 3 Sep 2004, Noorez Kassam wrote:
> I am getting some very strange results with my program. The first error i=
s
> that the input on the marked line, shows up on the next input line but ha=
s
> 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 inpu=
t
> 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 =3D getche();
> cout << endl;
> text_color(cGreen, cBlack);
>
> if(ask =3D=3D 'y' || ask =3D=3D '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 =3D FALSE;
> text_color(cRed,cBlack);
> clrs=3Dgetche(); //the character entered hear...
> cout << endl;
> text_color(cGreen,cBlack);
> if(clrs =3D=3D 'y' || clrs =3D=3D 'Y')
> {
> cLrs =3D TRUE;
> }
>
> else if(clrs =3D=3D 'n' || clrs =3D=3D 'N')
> {
> cLrs =3D FALSE;
> }
>
> else
> {
> cout << "What...";
> cout << "Default is set. No Clear Screen!\n";
> cLrs =3D FALSE;
> }
> //return to main test
> sYstem(cLrs);
> wait();
> return 0;
> }
>
> else if(ask =3D=3D 'n' || ask =3D=3D 'N')
> {
> cout << "Bye!" << endl;
> wait();
> cls();
> return 0;
> }
>
> else
> {
> cout << "What....\n" << endl;
> }
>
> }while(ask !=3D 'y' || ask !=3D 'Y' || ask !=3D 'n' || ask !=3D 'N');
>
> return 0;
> }
>
> //define the system function
> int sYstem(bool clrs)
> {
> char* drv =3D 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 =3D new char;
> if(coms =3D=3D 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 =3D strlen(coms);
> if(coms[comLen-1]=3D=3D ':')
> {
> delete drv;
> drv =3D new char;
> drv =3D coms;
> chdir(coms);
> strcat(drv,"\\>");
> delete coms;
> }
>
> if( strcmp(coms,"exit")=3D=3D0 || strcmp(coms,"bye")=3D=3D0 ||
> strcmp(coms,"quit")=3D=3D0 )
> {
> if(clrs =3D=3D TRUE)
> {
> cls();
> }
> return 0;
> }
>
> system(coms);
> delete coms;
>
> if(clrs =3D=3D TRUE)
> {
> wait();
> cls();
> }
>
> cout << endl;
> }//while
> }//end system def
>
> _________________________________________________________________
> Scan and help eliminate destructive viruses from your inbound and outboun=
d
> e-mail and attachments.
> http://join.msn.com/?pgmarket=3Den-ca&page=3Dbyoa/prem&xAPID=3D1994&DI=3D=
1034&SU=3Dhttp://hotmail.com/enca&HL=3DMarket_MSNIS_Taglines
> Start enjoying all the benefits of MSN=AE Premium right now and get the
> first two months FREE*.
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by BEA Weblogic Workshop
> FREE Java Enterprise J2EE developer tools!
> Get your free copy of BEA WebLogic Workshop 8.1 today.
> http://ads.osdn.com/?ad_id=3D5047&alloc_id=3D10808&op=3Dclick
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|