Linux does not have a way of conio.h solution

Source: Internet
Author: User

conio.his notCheader files in the standard library,ISOand thePOSIXare not defined in the standard.

Coniois aConsole input/output(console input and output), which defines the functions of data input and data output through the console. It is mainly the corresponding actions that some users produce by pressing the keyboard. For examplegetch ()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 include this header file, but already has its Compatibility pack, which can be included:

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, becauseLinuxThere is no such header file. In addition to using the above Compatibility Pack, you can alsoLinuxUsing native methods to achieve the same effect is to useLinuxcommand of the systemStty–echo. It does not show the input content, the source code for example.

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;

}

Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

Linux does not have a way of conio.h solution

Related Article

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.