blob: 9a9b7946c1fd7c38e1036dc810e135525fd4c0fe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
/*
* =====================================================================================
*
* Filename: gnu_history.c
*
* Description: testing GNU HISTORY AND GNU READLINE
*
* Version: 1.0
* Created: 02/05/2025 19:31:12
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/
#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>
#include <stdlib.h>
int main() {
char *input;
using_history(); // Initialize history
while (1) {
input = readline("shell> "); // Read user input
if (!input) break; // Handle Ctrl+D (EOF)
if (*input) { // If input is not empty
add_history(input); // Save input to history
}
printf("You typed: %s\n", input);
free(input); // readline() allocates memory, so free it
}
return 0;
}
|