Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

monomammoth

macrumors newbie
Original poster
Jun 10, 2010
5
0
I got books "objective-c for dummies" and "cocoa for dummies" when I'm inserting some codes from the book to my x-code (3.1.3.) is shows me errors.

Is there a difference between x-code versions in terms of actual programming codes? :confused:

thanks
 
The compiler is case sensitive, so even a capitalization difference will cause problems. Also, it's easy to forget semi-colons and other details. Cut and paste your code here and maybe we can help you spot where the problem is.
 
What are the errors? It's pointless to state "there are errors" and ask for help when you don't say what the errors are.

sorry for that, here is one example:

Code:
int a; 
	int b; 
	int c; 
	
	a = 1; 
	b = 2; 
	c=a+b;
	
	NSLog (@” a + b = %i”, c);
error: syntax error before '@' token
error: syntax error at 'OTHER' token 
	NSLog (@” a + b = %i”,a + b);  
error: syntax error before '@' token
error: syntax error at 'OTHER' token 
	NSLog (@” a still = %i”, a); 
	NSLog (@” b still = %i”, b); 
error: syntax error before '@' token
error: syntax error at 'OTHER' token 
	
    return 0;
}
 
How did you create your project in XCode? Was it an Command Line Tool with the Foundation classes or a Command Line Tool with the C code option set?
 
Cut/Paste the entire file. I suspect you're missing
Code:
#import <Foundation/Foundation.h>

Basically, an @ symbol is used in objective-c but not regular c. In order for the compiler (the thing that's kicking out errors at you) to know how to use the NSLog(), it needs to import the foundation framework (you may sometimes see the <Cocoa/Cocoa.h> declaration instead).
 
Cut/Paste the entire file. I suspect you're missing
Code:
#import <Foundation/Foundation.h>

Basically, an @ symbol is used in objective-c but not regular c. In order for the compiler (the thing that's kicking out errors at you) to know how to use the NSLog(), it needs to import the foundation framework (you may sometimes see the <Cocoa/Cocoa.h> declaration instead).

seems that it is the same, here is the screenshot:

Picture1-1.png
 
I think I figured it out. The " character you're using isn't the right one. When I cut/pasted your code in, it wasn't recognized as a string. When I replaced your " with my own it picked it up.
 
I think I figured it out. The " character you're using isn't the right one. When I cut/pasted your code in, it wasn't recognized as a string. When I replaced your " with my own it picked it up.



yeah that helped!, now it's working, thanks!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.