LoginSignup
2
2

More than 5 years have passed since last update.

コンソールプログラムでデバッグ文を表示する

Posted at

CUIプログラムで、画面を崩すことなくデバッグ文を表示したかった。以下の方法で今のところ上手く行ってます。

標準エラー出力にデバッグ文を出力するマクロを定義。(C99の__VA_ARGS__を使用)

#define debug(...) { fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); }

デバッグ文を散りばめ、プログラムをビルド。

debug("hello %s!", "world);

ターミナルで、以下を実行。

tail -f debug.log

コンソールプログラムを実行する際、標準エラー出力を上記のファイルにリダイレクトする。

your_cui_program 2> debug.log
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2