Hey is their a standard library that gives false and true values or something or are you suppose to assign them?? Im writing a function that suppose to return true or false. And i also tried replacing the words true and false by !0 (true) and 0 (false) but my program gives me a weird segmentation fault with the replaced words and without. Could someone give me some advice?

Recommended Answers

All 5 Replies

why would you define TRUE as 0 and FALSE as 1?

TRUE and FALSE are defined, as 1 and 0 respectively, in stdbool.h for C99.

if you're unsure do this:

#ifndef FALSE
#define FALSE (0)
#endif
#ifndef TRUE
#define TRUE (1)
#endif

why would you define TRUE as 0 and FALSE as 1?

TRUE and FALSE are defined, as 1 and 0 respectively, in stdbool.h for C99.

if you're unsure do this:

#ifndef FALSE
#define FALSE (0)
#endif
#ifndef TRUE
#define TRUE (1)
#endif

the reason i put that is cause our teacher told us, "to return false (!0) and true (0)" i thought it was a hint to replace the true and false with the paranthesized numbers. Does the code that you gave me have to be in a separate file? or could it be included in the current file im working all my functions in?

the reason i put that is cause our teacher told us, "to return false (!0) and true (0)" i thought it was a hint to replace the true and false with the paranthesized numbers. Does the code that you gave me have to be in a separate file? or could it be included in the current file im working all my functions in?

Im sorry I had it written wrong, two times. I meant to say that false (0) and true (!0).

>Could someone give me some advice?
Not without seeing any code, no. Your problem appears to be a runtime error more than confusion about true and false.

>TRUE and FALSE are defined, as 1 and 0 respectively, in stdbool.h for C99.
They're both lower case, actually:

#define bool _Bool
#define false 0
#define true 1

However, TRUE and FALSE are rather common macros as well.

Im sorry I had it written wrong, two times. I meant to say that false (0) and true (!0).

well, then, as narue said they are lowercase, so define them if they aren't already defined.

#ifndef false
#define false (0)
#define true (!0)
#endif

and use them in code like so if (value == true) { ... or whatever you're doing

.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.