次の例では、boolean
の変数の値をスキャンしようとしています。私はGCCでコンパイルすると、私は警告以下の取得、Cのboolの書式指定子はありますか?
warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘_Bool *’ [-Wformat=]
scanf("%d",&b);
コード:
#include <stdio.h>
#include <stdbool.h>
int main()
{
bool b;
scanf("%d",&b);
printf("%d\n",b);
}
私の質問は、ブール値のいずれかの書式指定子がC
にありますか? printf
についてはC.
でbool
タイプには書式指定子がありません
。代わりに、 'printf("%s \ n "、b?" true ":" false ");'を使用することもできます。 –
これは印刷に関するものであり、http://stackoverflow.com/questions/12920694/format-specifier-in-scanf-for-bool-datatype-in-cは 'scanf()に関するものなので、これは100%dupeではありません。 '。しかし、まだ、十分に私は推測する。 :) – unwind
@unwind:あなたは正しい。私は謝罪して再開する。今度はCの標準を掘り下げる時です。 – Bathsheba