add: API function put will write to fstream

This commit is contained in:
2024-01-18 16:34:47 +01:00
parent b479cf3dea
commit 0abe351697

View File

@@ -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--]);
}
}