Implementation of flip function

zhaozj2021-02-16  57

In a UNIX environment, when we encounter large data output, you will usually add such a function - pressing any key to continue ... Is this functional implementation as simple as the code below?

#include

Main ()

{

Printf ("press any key to continue ... / n");

GetChar ();

Printf ("press any key to continue ... / n");

GetChar ();

}

Debugging, you will find that every time you enter the Enter must be used to take effect, so our "according to any means to continue ..." It is better to change to "Continue by ENTER button ...". But at a responsible attitude, we should still consider how to implement "according to any means to continue ...". Here, the setting problem for the input terminal, the simple code below will tell us the specific implementation steps:

#include

#include

Main (Argc, Argv)

Int argc;

Char ** argv;

{

Struct sgttyb sgo, sgn;

Struct tchars TCO, TCN;

/ * Get current mode and setup * /

IOCTL (0, Tiocgetp, & SGO);

IOCTL (0, Tiocgetc, & Tco);

SGN = SGO;

Sgn.sg_flags & = ~ echo; / * Close Echo * /

SGN.SG_FLAGS | = CBREAK; / * Open CBREAK * /

TCN = TCO;

TCN.T_INTRC = -1; / * Failure to the interrupt button * /

/ * Save new mode and set * /

IOCTL (0, TiocSetp, & SGN);

IOCTL (0, TiocSetc, & TCN);

/ * Add "to continue ..." Features * /

Printf ("press any key to continue ... / n");

GetChar ();

Printf ("press any key to continue ... / n");

GetChar ();

/ * Reset old mode and set * /

IOCTL (0, TiocSetp, & SGO);

IOCTL (0, TiocSetc, & Tco);

exit (0);

}

Ok, now our "according to any means, continue ..." can be assured to run.

The above code is debugged under UNIX AIX 4.3.0.

转载请注明原文地址:https://www.9cbs.com/read-22331.html

New Post(0)