Ubuntu uses conio.h under Windows

Source: Internet
Author: User

Paste the contents of the dashed box into the text of the document

----------------------------------------------------------------------------------------------------------

#include <termios.h>
#include <stdio.h>


static struct Termios old, new;


/* Initialize new terminal I/O settings */
void Inittermios (int echo)
{
Tcgetattr (0, &old); /* Grab old terminal I/O settings */
new = old; /* Make new settings same as old settings */
New.c_lflag &= ~icanon; /* Disable buffered I/O */
New.c_lflag &= Echo? ECHO: ~echo; /* Set echo Mode */
Tcsetattr (0, Tcsanow, &new); /* Use these new terminal I/O settings now */
}


/* Restore old terminal I/O settings */
void Resettermios (void)
{
Tcsetattr (0, Tcsanow, &old);
}


/* Read 1 Character-echo defines echo mode */
char getch_ (int echo)
{
Char ch;
Inittermios (Echo);
ch = getchar ();
Resettermios ();
return ch;
}


/* Read 1 character without echo */
Char getch (void)
{
Return Getch_ (0);
}


/* Read 1 character with Echo */
Char getche (void)
{
return Getch_ (1);
}


/* Let's Test it out */

----------------------------------------------------------------------------------------------------

Save As to/usr/include/conio.h

Ubuntu uses conio.h under Windows

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.