From 255a93c5e5a27fb0d1b0935f78e54a428dc752c2 Mon Sep 17 00:00:00 2001 From: anon <anon@anon.anon> Date: Sun, 10 Mar 2024 15:57:35 +0100 Subject: [PATCH] Added gnu_history.c --- gnu_history.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 gnu_history.c diff --git a/gnu_history.c b/gnu_history.c new file mode 100644 index 0000000..ae6816e --- /dev/null +++ b/gnu_history.c @@ -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; +}