在同一个程序中添加GNU Readline和ncurses库,可以使用以下步骤:
sudo apt-get install libreadline-dev libncurses5-dev
#include <readline/readline.h>
#include <ncurses.h>
#include<stdio.h>
#include <readline/readline.h>
#include <ncurses.h>
int main() {
char *input;
char *prompt = "Enter a command: ";
// Initialize ncurses
initscr();
raw();
keypad(stdscr, TRUE);
noecho();
// Use GNU Readline to get input
input = readline(prompt);
// Print the input
printf("You entered: %s\n", input);
// Clean up ncurses
endwin();
// Free memory allocated by readline
free(input);
return 0;
}
gcc -o my_program my_program.c -lreadline -lncurses
这样,程序就可以同时使用GNU Readline和ncurses库了。
领取专属 10元无门槛券
手把手带您无忧上云