PDA

View Full Version : Learning Code




oxxygenn
Jul 19, 2012, 08:47 PM
Hi there,

Just starting out learning objective C, and i tried to make a simple code for starters, however on every "NSLog" line it says "expected expression" and i can not figure out why. On the line "Hello World", it also says "Implicit declaration of function "NSLog" is invalid in C99".


int main(int argc, const char * argv[])
{
int a;
int b;
int c;

a = 1;
b = 2;
c = a + b;

NSLog(@"Hello World");
NSLog(@" a + b = %i", c);
NSLog(@" a + b = %i", a + b);
NSLog(@" a = %i", a);
NSLog(@" b = %i", b);

return 0;
}


Also, if anyone has any good tutorials they know of for me to learn it would be appreciated, thank you.



robvas
Jul 19, 2012, 09:07 PM
n/m

oxxygenn
Jul 19, 2012, 09:11 PM
n/m
sorry forgot to copy that part
#import ,Foundation/Foundation.h>

int main(int argc, const char * argv[])
{
int a;
int b;
int c;

a = 1;
b = 2;
c = a + b;

NSLog(@"Hello World");
NSLog(@" a + b = %i", c);
NSLog(@" a + b = %i", a + b);
NSLog(@" a = %i", a);
NSLog(@" b = %i", b);

return 0;

, instead of < fixed my problem haha thank you for the help

chown33
Jul 19, 2012, 09:15 PM
What is the filename?

If it's something.c then it will be compiled as a C program, and C has no idea what @" means. I think this is a likely cause of the "expected expression" error. Change the filename to something.m, then add this as the first line:
#import <Foundation/Foundation.h>

Does that solve the problem?


What tutorials are you using now? If it's none, then what have you read about C and/or Objective-C? Please be specific, even if it's to say you've read nothing and are writing code based on random google searches.

What is your computer language experience? Do you know other languages? Do you know anything at all about programming?

----------

When posting code, please post complete code, from the start of the file to its end.

Because you're missing a closing } in what you posted, in addition to the , for < typo.