Browse Source

use readline instead of fputs() & fgets()

master
T. Meissner 5 years ago
parent
commit
6344b1c057
2 changed files with 11 additions and 9 deletions
  1. +1
    -1
      chapter_04/Makefile
  2. +10
    -8
      chapter_04/prompt.c

+ 1
- 1
chapter_04/Makefile View File

@ -2,7 +2,7 @@ all: prompt
%: %.c
cc -std=c11 -Wall $@.c -o $@
cc -std=c11 -Wall $@.c -ledit -o $@
.PHONY: clean


+ 10
- 8
chapter_04/prompt.c View File

@ -1,8 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
/* Declare a buffer for user input of size 2048 */
static char input[2048];
#include <editline/readline.h>
int main(int argc, char const *argv[])
@ -13,14 +12,17 @@ int main(int argc, char const *argv[])
/* 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 max size 2014 */
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;


Loading…
Cancel
Save