|
|
#1 |
|
Newbie C Question
Hello,
I'm trying to teach myself programming and I'm having problems already. When I add #include <c.h> I get an error message of "No such File or Directory" in X-Code. Any help would be appreciated. Thanks |
|
|
|
0
|
|
|
#2 |
|
I don't think c.h exists...why did you want to include this?
__________________
Mac Pro 8 core 2.8Ghz, 8800GT, 8GB RAM, 1.3TB iPad 2 Black 64GB Verizon MBP 15" 2.4Ghz Glossy:4GB RAM,160GB 7200RPM HDD Nikon D7000 and D90: 70-200mm 2.8 VR2, 24-70 2.8, 50mm 1.8 |
|
|
|
0
|
|
|
#3 |
|
You want to do #import <stdlib.h> or #import <stdio.h>
__________________
If they have to tell you every day they are fair you can bet they arent, if they tell you they are balanced then you should know they are not - Don't Hurt me |
|
|
|
0
|
|
|
#4 |
|
I'm trying to add True/False logical operators to a simple program. From the book "Learn C on Mac OS X.
Thanks |
|
|
|
0
|
|
|
#5 |
|
u should use
Code:
#import <stdlib.h> #import <stdio.h>
__________________
Macbook 1gb Ram 2.10ghz 120gb HD Leopard iphone 3g 8gbXbox360(Italiano40) |
|
|
|
0
|
|
|
#6 |
|
When I change it to <stdlib.h> I still get a second error that reads " 'true' undeclared (first use in this function). The strange thing is the example program runs fine. But when I make my own program I still get those two error messages. This includes a copy/paste of the example.
|
|
|
|
0
|
|
|
#7 | |
|
Quote:
__________________
Mac Pro 8 core 2.8Ghz, 8800GT, 8GB RAM, 1.3TB iPad 2 Black 64GB Verizon MBP 15" 2.4Ghz Glossy:4GB RAM,160GB 7200RPM HDD Nikon D7000 and D90: 70-200mm 2.8 VR2, 24-70 2.8, 50mm 1.8 |
||
|
|
0
|
|
|
#8 |
|
#include <stdlib.h> //needed this to get definition of true
#include <stdio.h> int main (int argc, const char * argv[]) { int hasCar, hasTimeToGiveRide; int nothingElseOn, newEpisode, itsARerun; hasCar = true; hasTimeToGiveRide = true; if ( hasCar && hasTimeToGiveRide ) printf( "Hop in - I'll give you a ride!\n" ); else printf( "I've either got no car, no time, or both!\n" ); nothingElseOn = true; newEpisode = true; if ( newEpisode || nothingElseOn ) printf( "Let's watch Star Trek!\n" ); else printf( "Something else is on or I've seen this one.\n" ); nothingElseOn = true; itsARerun = true; if ( nothingElseOn || (! itsARerun) ) printf( "Let's watch Star Trek!\n" ); else printf( "Something else is on or I've seen this one.\n" ); return 0; } |
|
|
|
0
|
|
|
#9 |
|
I don't believe C natively has booleans, you have to use 1 and 0 AFAIK...
__________________
If they have to tell you every day they are fair you can bet they arent, if they tell you they are balanced then you should know they are not - Don't Hurt me |
|
|
|
0
|
|
|
#10 |
|
Correct, C does not define true or false (or TRUE or FALSE as it would more likely be in C). I think the only constant defined in stdlib is NULL.
|
|
|
|
0
|
|
|
#11 |
|
Thank you. But why would it run sometimes (from the example) and not others? Thanks again for your help.
|
|
|
|
0
|
|
|
#12 | |
|
Quote:
Generally, header files vary from system to system and from one library implementation to the next. Booleans, an in-built type in C++, are in C a #define or an enumerated type, i.e. Code:
#define FALSE 0 #define TRUE 1 Code:
enum Boolean {false, true}; /* i.e., false=0, true=1 */
__________________
all Jarvis, all the time Last edited by yeroen; May 17, 2008 at 05:01 PM. |
||
|
|
0
|
|
|
#13 |
|
You can use #include<stdbool.h>
|
|
|
|
0
|
|
|
#14 |
|
Have you checked here:
http://www.spiderworks.com/extras/index.php To see if that header file (c.h) is available for download? If the book's examples rely heavily on it (which would be a bit depressing anyway) you should probably have it handy. It does seem strange that the #include preprocessor directive uses chevrons (<>) and not quotes, as chevrons generally mean "look in system include directories" and quotes mean "look in the current directory". It seems off that a book would ask you to put a header they provide in a system directory. Good luck! -Lee P.S. I guess the right thing to call <> is angle brackets, not chevrons. That's what I've always heard them called, but maybe it's because I say it first in conversation and my first CS teacher taught me that way or something. |
|
|
|
0
|
|
|
#15 |
|
Thanks to everyone for your help.
#define FALSE 0 #define TRUE 1 That let the code compile. I'm sure I'll have more questions as I travel down this path. Thanks |
|
|
|
0
|
|
|
#16 |
|
We all love C questions. The more arcane the better (it's our chance to show off)
__________________
all Jarvis, all the time |
|
|
|
0
|
|
|
#17 |
|
C standard from 1999 ("C99") supports booleans
Stolen from http://www.comeaucomputing.com/techtalk/c99/#bool :
What Are _Bool and bool? C99 now supports a boolean type _Bool and also bool via <stdbool.h>. Consider: #include <stdio.h> int main() { // _Bool can hold 0 or 1 // _Bool is an unsigned integer type _Bool b = 1; struct xyz { _Bool mem : 1; // _Bool bitfields allowed }; printf("%d\n", b); // 1 b = 0; printf("%d\n", b); // 0 _Bool *pb = &b; // If the expression evaluates to 0, then it converts to _Bool as 0, else 1 b = pb; printf("%d\n", b); // 1 b = -1; printf("%d\n", b); // 1 b = (pb == 0); printf("%d\n", b); // 0 return 0; } // #define's bool, true, false, __bool_true_false_are_defined macros // as _Bool, 1, 0, and 1 respectively #include <stdbool.h> void foo() { int this = 99; int that = -99; bool b; if (this || that) b = true; else b = false; }
__________________
GNU/Linux on a Mac Pro 8-core, 5GB RAM, 1.25TB storage. Free thyself. |
|
|
|
0
|
|
|
#18 |
|
By the way: #import is not C (it's Objective-C). Just use #include.
__________________
Computer Programming: An Introduction for the Scientifically Inclined So how much does an iPhone developer make? My iPhone games: Sjoelen, Mazer (free) |
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| thread | Thread Starter | Forum | Replies | Last Post |
| Newbie question about Xcode 4 | Apple2 | iPhone/iPad Programming | 2 | Apr 16, 2011 05:03 PM |
| Apple Newbie/Pre-Switch Questions | LameBolus | Switch Stories | 8 | Jun 21, 2003 02:07 PM |
| newbie iTunes question | davrouk | Mac Applications and Mac App Store | 10 | May 19, 2003 02:03 AM |
| newbie printing question | imacryan | Mac Applications and Mac App Store | 6 | May 9, 2003 02:23 PM |
| Mac Newbie with questions regarding RAM | lpj8 | General Mac Discussion | 4 | Nov 18, 2002 09:50 PM |
All times are GMT -5. The time now is 10:41 PM.







Macbook 1gb Ram 2.10ghz 120gb HD Leopard
Linear Mode

