From e0072175f5195088542b6080ec55102ecbaa1b05 Mon Sep 17 00:00:00 2001 From: dx Date: Thu, 7 May 2020 01:23:45 +0100 Subject: +!fix for REPL bug with missing end tags When using fgets(), the returned string doesn't have a null terminator but rather a newline (you use a RET to end input). So I made a little script portion dedicate to finding the first newline and wholly removing it. --- Converter/src/main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'Converter') diff --git a/Converter/src/main.c b/Converter/src/main.c index fbcd938..f9c96a3 100644 --- a/Converter/src/main.c +++ b/Converter/src/main.c @@ -24,12 +24,19 @@ int main(int argc, char *argv[]) else { + int i; + char *buf; while (1) { + printf("> "); - char *buf = malloc(sizeof(*buf) * 1024); + buf = malloc(sizeof(*buf) * 1024); fgets(buf, 1024, stdin); - string output = (compile_line(buf, 1024, "")); + + for (i = 0; buf[i] != '\n'; ++i) continue; + buf[i] = '\0'; // terminate + + string output = (compile_line(buf, strlen(buf), "")); puts(output); free(output); } -- cgit v1.2.3-13-gbd6f