LoginSignup
0
0

More than 5 years have passed since last update.

[RaspberryPi]printf()が使えない??

Last updated at Posted at 2015-10-10

RaspberryPi(に限らずかもしれませんが)にてprintf()を使うときは、改行が入るまではコンソールに文字が出力されません。
Raspberry Pi: printf() doesn't work with wiringPi

日本語キーボードでは¥/バックスラッシュが入れられないので、横着して\nを省略していると出力されない、という間抜けな話です。
これにはまってしまい、Stackoverflowで質問した次第です。恥ずかしっ

stdoutが標準でline-bufferedであることに起因しており、
改行のほか、fflush()を使うことでも出力できるそうです。

stdout by default is line-buffered, meaning it tries to put off writing stdout by default is line-buffered, meaning it tries to put off writing data to the underlying file until a newline. But since you never print a newline, stdout will just buffer your text until it runs out of space.
You can fix this by either adding a newline in the format string (i.e. "%d\n"), or calling fflush on stdout after printing.

質問の投稿からしばらく経ちますが、ふと思い出したので記事にしてみました。

0
0
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
0
0