-
boolean.c
Hi I am having problems compiling this program they are 3 errors in line 7. Can you help me find the problem?
Thanks for your help.
boolean.c(7) : error C2065: 'Bool' : undeclared identifier
boolean.c(7) : error C2146: syntax error : missing ';' before identifier 'input_is_good'
boolean.c(7) : error C2065: 'input_is_good' : undeclared identifier
Error executing cl.exe.
Code:
// boolean.c -- using a _Bool variable
#include <stdio.h>
int main(void)
{
long num;
long sum = 0L;
_Bool input_is_good; //where the error is
printf("Please enter an integer to be summed. ");
printf("Enter q to quit.\n");
input_is_good = (scanf("%ld", &num) == 1);
while (input_is_good)
{
sum = sum + num;
printf("Please enter next integer to be summed. ");
printf("Enter q to quit.\n");
input_is_good = (scanf("%ld", &num) == 1);
}
printf("Those integers sum to %ld.\n", sum);
return 0;
}
-
it says _Bool does not exist, perhaps it is capitalized differently.
-
To use _Bool you need to include the appropriate header and have a C99 compiler. _Bool is in stdbool.h.
Quzah.
-
>_Bool is in stdbool.h.
_Bool is a data type in C99, you don't need to include any headers. You do need to include stdbool.h to get the bool, true, and false macros though.
-
You're trying to compile c99 on a microsoft compiler and microsoft compilers don't support c99. Perhaps you should consider getting yourself a compiler which does, such as MinGW (Dev-cpp, code::blocks are popular ides for this).
>>stdbool.h <<
Microsoft compilers don't have stdbool.h(msvc7 and msvc8 don't).
-
Thank you guys
I learn something today. I was running it on a windows compiler visual studio c++ 6.0 but it didint work as you said the compiler didint support it. When i ran the program on a linux compiler gcc works perfect.
Thanks and have a nice day
-
Or you could use BOOL (C compiler) or bool (C++ compiler) instead if you want it to compile on Windows.
-
>Or you could use BOOL (C compiler) or bool (C++ compiler) instead if you want it to compile on Windows.
Or you could use an unsigned char, get the same effect, and have it compile everywhere. :rolleyes: