No conio.h solution in Linux

Source: Internet
Author: User

conio.his notCheader files in the standard library,ISOand thePOSIXThere are no definitions in the standard. Coniois aConsole input/output(console input and output), which defines the functions of data input and data output through the console, mainly by the user by the keyboard-generated corresponding actions, such asgetch ()functions, and so on. MostDOS,Windows,Phar Lap,Dosx,OS/2and other platforms on theCThe compiler provides this file,UNIXand theLinuxPlatform forCThe compiler itself usually does not contain this header file, but already has its Compatibility pack, which can be consulted:

http://conio.sourceforge.net/

In addition, we usually use the mainconio.hin this header file,getch ()function, which reads the keyboard character but does not display it (without Echo), but containsconio.hthe program inLinuxcannot be compiled directly through, becauseLinuxwithout this header file, in addition to using the above compatibility package can also beLinuxusing native methods to achieve the same effect is to useLinuxcommand of the systemStty–echo, it does not display the input content, the source code is as follows.

In Windows

#include <stdio.h>

#include <conio.h>

int main () {

char c;

printf ("Input a char:");

C=getch ();

printf ("You have inputed:%c \ n", c);

return 0;

}

In Linux

#include <stdio.h>

int main () {

char c;

printf ("Input a char:");

System ("Stty-echo");

C=getchar ();

System ("Stty echo");

printf ("You have inputed:%c \ n", c);

return 0;

}

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.