boolean.c

This is a discussion on boolean.c within the C Programming forums, part of the General Programming Boards category; Hi I am having problems compiling this program they are 3 errors in line 7. Can you help me find ...

  1. #1
    wise_ron wise_ron's Avatar
    Join Date
    May 2006
    Posts
    75

    Question 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;
    }
    Wise_ron
    One man's constant is another man's variable

  2. #2
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    it says _Bool does not exist, perhaps it is capitalized differently.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    To use _Bool you need to include the appropriate header and have a C99 compiler. _Bool is in stdbool.h.


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >_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.
    My best code is written with the delete key.

  5. #5
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    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).
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  6. #6
    wise_ron wise_ron's Avatar
    Join Date
    May 2006
    Posts
    75

    Talking 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
    Wise_ron
    One man's constant is another man's variable

  7. #7
    Registered User SKeane's Avatar
    Join Date
    Sep 2006
    Location
    England
    Posts
    234
    Or you could use BOOL (C compiler) or bool (C++ compiler) instead if you want it to compile on Windows.

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >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.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21