[Courses] re: [C] lesson 7

Eugene Teo eugene.teo at eugeneteo.net
Wed Nov 6 16:37:52 EST 2002


There isn't a need to do a symbolic constant for boolean.
Just remember that if it is 0, then it is false. Anything else is true.

Hardcoding a boolean self-defined type would only make the program look
a little more confusing than required later on.

<quote who="Bidea Cristian">
u> 
u>  
u> I don't know if this is absolutely necessary, but I want to make some observations:
u> 
u> 
u> It seems that the C programming language doesn't have BOOLEAN,
u> in it like Pascal does. In Pascal, the Boolean data type returns
u> true or false. So, using the Boolean type, Pascal programmers
u> can create functions (procedures) like: isvowel(ch), or isdigit(ch).
u> --------------------------------
u> 
u> OK! Is true, in C there is no boolean data, but (there is but :-) you can simulate the boolean data. The boolean data is practically an integer data type that can have only two values 0 and 1. But in other languages you can say "true" instead of 1 and "false" instead of 0. You can do this this in C with the #define directive:
u> 
u> #define boolean int
u> 
u> #define false 0
u> 
u> #define true 0
u> 
u> Or in C++ with
u> 
u> typedef enum boolean{false, true};
u> 
u> OK! That's all! Bye! Peace :)
u> 
u> -----------------------------
u> The C Standard library does have the following predefined functions
u> in the header:
u> 
u> Function | Description
u> ---------+------------------------------------
u> isalnum | Test for Alphanumeric
u> isalpha | Test for Alphabetic
u> iscntrl | Test for Control Character
u> isdigit | Test for Digit
u> isgraph | Test for Graphical Character
u> islower | Test for Lower-Case Letter
u> isprint | Test for Printing Character
u> ispunct | Test for Punctuation Character
u> isspace | Test for White-Space Character
u> isupper | Test for Upper-Case Letter
u> isxdigit | Test for Hex Digit
u> ---------+-------------------------------------
u> 
u> Happy Programming!
u> --
u> K
u> 
u> On Sun, Nov 03, 2002 at 04:29:39PM -0500, Morgon Kanter wrote:
u> > Hello,
u> > 
u> > After doing the lesson 7 excercises, I thought it would be a good idea to 
u> > make a header file of some of the common stuff we'd been doing. So here is 
u> > one of the excercises.
u> > 
u> > char consonent_or_vowel(char letter) {
u> > char returnchar[10];
u> >
u> > 
u> > 
u> > returnchar = "consonent";
u> > break;
u> > default:
u> > returnchar = "vowel";
u> > break;
u> > }
u> > return returnchar;
u> > }
u> > 
u> > If I made an error, please let me know.
u> > 
u> 
u> 
u> 
u> 
u> ---------------------------------
u> Do you Yahoo!?
u> HotJobs - Search new jobs daily now
-- 
eMail: eugeneteo at eugeneteo.net, eugeneteo at null.cc.uic.edu
gpg pub_key: http://null.cc.uic.edu/~eugeneteo/eugeneteo.asc
main(i){putchar(182623909>>(i-1)*5&31|!!(i<7)<<6)&&main(++i);}




More information about the Courses mailing list