8c0573d6813e4201e91d6535b9e370a766172ab2 — EuAndreh 3 months ago 4fc4c40
Use readline instead of fgets
1 files changed, 11 insertions(+), 7 deletions(-)

M prompt.c
M prompt.c => prompt.c +11 -7
@@ 1,7 1,8 @@ #include <stdio.h>
+ #include <stdlib.h>
  
- /* Declare a bufferfor user input of size 2048 */
- static char input[2048];
+ #include <editline/readline.h>
+ // #include <editline/history.h>
  
  int main(int argc, char** argv) {
  


@@ 12,14 13,17 @@ /* In a never ending loop */
    while (1) {
  
-     /* Output our prompt */
-     fputs("lispy> ", stdout);
+     /* Output our prompt and get input */
+     char* input = readline("lispy> ");
  
-     /* Read a line of user input of maximum size 2048 */
-     fgets(input, 2048, stdin);
+     /* Add input to history */
+     add_history(input);
  
      /* Echo input back to user */
-     printf("No you're a %s", input);
+     printf("No you're a %s\n", input);
+ 
+     /* Free retrieved input */
+     free(input);
    }
  
    return 0;