sprintf(s,"%*d: %s",digit(l),i * up + start,tmp);の%*dは何を意味しているか教えていただきたいです。
tmpが%sの部分に入っているのは理解できるのですが、digit(l)とi * upの2つがこの場合はどこに入っている扱いになるのかが理解できないです。
i,up,startはint型です。
tmpはchar型のポインタです。
digitの関数の中身は
return (int)ceil(log10(x+1));
の一文のみです。
%*dについて
Re: %*dについて
printfにもともと備わっている機能です。あんどーなつ さんが書きました: Visual Studioでできるかはしらないです(GCC拡張仕様の可能性あり)
できない処理系があったら知りたいくらいです。
バグのないプログラムはない。
プログラムは思ったとおりには動かない。書いたとおりに動く。
プログラムは思ったとおりには動かない。書いたとおりに動く。
Re: %*dについて
printf系の関数では、出力幅や精度のかわりに*を用いることで、出力するデータの前に置くint型の引数でそれらの値を指定することができます。
N1570 7.21.6.1 The fprintf functionの5より引用
N1570 7.21.6.1 The fprintf functionの5より引用
N1570 7.21.6.6 The sprintf functionの2より引用As noted above, a field width, or precision, or both, may be indicated by an asterisk. In
this case, an int argument supplies the field width or precision. The arguments
specifying field width, or precision, or both, shall appear (in that order) before the
argument (if any) to be converted. A negative field width argument is taken as a - flag
followed by a positive field width. A neg ative precision argument is taken as if the
precision were omitted.
The sprintf function is equivalent to fprintf, except that the output is written into
an array (specified by the argument s) rather than to a stream.
複雑な問題?マシンの性能を上げてOpenMPで殴ればいい!(死亡フラグ)