Noob Q, best-practices related:
I'm writing a MS BASIC interpreter for macOS using yacc/lex/C. It uses scanf
/printf
for PRINT
and INPUT
. I would like to add a CLI option to redirect those to files.
I know how to do this technically, using fopen/fclose and fprintf etc.. But is that how "real" Unixen programs would do it? I would like to be as standard as possible to avoid confusion when someone else examines the code.
On generic Unix/Linux/FBSD, would you...
- replace all the
printf
withfprintf(fp,
and defaultfp
to stdout? - keep all the
printf
s but redirectstdout
? - rely on the shell and piping and not offer this as a CLI option at all?