Functions interchange between the curses Library and the conio Library

Source: Internet
Author: User
They can conquer who believe they can .--Virgil

CursesIs a UNIX-like systemTerminal control libraryUsed to build the application of the text User Interface [text User Interface (tui )]Program. The name is derived from pun on [cursor optimization ]. It is used to manage applications that use character terminals (character-cell terminals) as interfaces, such as VT100.

Curses-based softwareTypes of Software generally implement the curses library or its compatible Library (such as the ncurses library ). The curses library is mainly used to create "Graphical" applications on character devices, such as common SSH and Telnet clients. When using some programs, the simulated GUI is displayed as a character.

Curses are usually used in Unix-like systems, but they are also implemented in windows.ConioLibrary to complete similar tasks.

 

This function is usually implemented by using the conio library on windows. You need to replace it with the curses library when porting it to Linux. Add [-Lcurses] Parameters.

$ GCC test. C-lcurses

Test. C: 2: 27: Error: Curses. h: the file or directory does not exist.

 

 

This error occurs because the corresponding curses library is not installed. In ubuntu, you can use the following statement to install the curses library.

$ Sudo apt-Get install libncurses5-dev

For example, the following program reads user-input characters from the command line and determines whether the character is Q

"★ 

 
/* Turbo C version */# include <stdio. h> # include <conio. h> intmain (void) {char C; while (C = getch ())! = 'Q') {printf ("You have enter % C \ n", c );}}

To run the preceding program on Linux, you must use the functions provided by the curses library.

"★ 

 
/* Use the cursee library to obtain characters from the client */# include <stdio. h> # include <curses. h> intmain (void) {char C; int ROW = 0; int Col = 0; initscr (); While (C = getch ())! = 'Q') {// move the cursor to the row, Col column move (row ++, col); // call the delch () insch () function, use C to replace the current character delch (); insch (c) ;}endwin (); Return 0 ;}

Note that when using the curses library function, you must first use the initscr () function to initialize the window. At the end of the program, call endwin () to return to the console and exit.

"★

/* cursee library template */# include 
  
    # include 
   
     intmain (void ){... initscr ();... endwin ();... 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.