add: API function put will write to fstream
This commit is contained in:
@@ -11,14 +11,18 @@ void api_put() {
|
|||||||
int mode = state->STACK[state->STACK_IDX--]; // 1 for char, 2 for num
|
int mode = state->STACK[state->STACK_IDX--]; // 1 for char, 2 for num
|
||||||
if (mode != 1 && mode != 2) return;
|
if (mode != 1 && mode != 2) return;
|
||||||
|
|
||||||
|
FILE *f = fstream;
|
||||||
|
if (f == stderr)
|
||||||
|
f = stdout;
|
||||||
|
|
||||||
if (mode == 1) {
|
if (mode == 1) {
|
||||||
char c = state->STACK[state->STACK_IDX--];
|
char c = state->STACK[state->STACK_IDX--];
|
||||||
if (c == '\0') c = ' ';
|
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 {
|
else {
|
||||||
printf("%d", state->STACK[state->STACK_IDX--]);
|
fprintf(f, "%d", state->STACK[state->STACK_IDX--]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user