Added gnu_history.c
This commit is contained in:
parent
703455ebad
commit
255a93c5e5
23
gnu_history.c
Normal file
23
gnu_history.c
Normal file
@ -0,0 +1,23 @@
|
||||
// @COMPILECMD gcc $@ -lreadline -lhistory
|
||||
#include <stdio.h>
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
|
||||
int main() {
|
||||
using_history(); // Initialize history
|
||||
|
||||
char *input;
|
||||
while ((input = readline("Enter your command: ")) != NULL) {
|
||||
if (input[0] != '\0') {
|
||||
add_history(input); // Add to history
|
||||
// Process and handle input here
|
||||
printf("You entered: %s\n", input);
|
||||
}
|
||||
free(input); // Free allocated memory
|
||||
}
|
||||
|
||||
// Save history to a file (optional)
|
||||
write_history("history.txt");
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user