プログラムをコンパイルしようとしていますが(リスト12.13 - CのPrimer Plus 6th Editionからのmanydice.c)、コンパイルエラーが発生しています: 'status' undeclaredこの機能で使用してください)。コントロールセクション内のCで変数を宣言するときのコンパイル時エラー
「どこでも宣言する」というc99標準についての説明にも感謝します。ここ
は、コードの一部である:
int main(void)
{
int dice, roll;
int sides;
srand((unsigned int) time(0)); /* randomize seed */
printf("Enter the number of sides per die, 0 to stop.\n");
while(scanf("%d", &sides) == 1 && sides > 0)
{
printf("How many dice?\n");
if((status = scanf("%d", &dice)) != 1)
{
if(status == EOF)
{
break; /* exit loop */
}
...
エラーメッセージがある:
||=== Build: Debug in dice (compiler: GNU GCC Compiler) ===|
~manydice.c||In function 'main':|
~manydice.c|19|error: 'status' undeclared (first use in this function)|
~manydice.c|19|note: each undeclared identifier is reported only once for each function it appears in|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
オプション:(コードを使用::ブロックバージョンは、GCC 4.9.2を示す--gcc 16.01 MinGWの32ビット、Windows 7 Ultimate 32ビット)
mingw32-gcc.exe -Wall -g -std=c99 -c
このエラーはなぜ発生しますか?
あなたが使用している変数 'status'を*定義していない*ためです。 –
あなたのコードには、 'status'を宣言しようとするようなものはありません。それはどこで宣言されたと思いましたか? –
@ Wumpus Q. Wumbley私が学んでいるように、この本(この本と同じように入力したもの)からこの例を学んでいて、それがコンパイルされず、何が間違っているのかわからないので、この質問をします。 – spaceout