From 0abe3516971ccc98517762c6727bcfcabd02e00a Mon Sep 17 00:00:00 2001 From: ALittlePatate Date: Thu, 18 Jan 2024 16:34:47 +0100 Subject: [PATCH] add: API function put will write to fstream --- src/api.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/api.c b/src/api.c index 467d520..65d1a07 100644 --- a/src/api.c +++ b/src/api.c @@ -11,14 +11,18 @@ void api_put() { int mode = state->STACK[state->STACK_IDX--]; // 1 for char, 2 for num if (mode != 1 && mode != 2) return; + FILE *f = fstream; + if (f == stderr) + f = stdout; + if (mode == 1) { char c = state->STACK[state->STACK_IDX--]; if (c == '\0') c = ' '; - printf("%c", c); //using printf and not write because of the buffer + fprintf(f, "%c", c); //using printf and not write because of the buffer } else { - printf("%d", state->STACK[state->STACK_IDX--]); + fprintf(f, "%d", state->STACK[state->STACK_IDX--]); } }