Learning Code

Discussion in 'Mac Programming' started by oxxygenn, Jul 19, 2012.

  1. macrumors newbie

    Joined:
    Jan 14, 2011
    #1
    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".

    Code:
     
    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.
     
  2. macrumors 68000

    Joined:
    Mar 29, 2009
    Location:
    USA
    #2
    n/m
     
  3. thread starter macrumors newbie

    Joined:
    Jan 14, 2011
    #3
    sorry forgot to copy that part
    Code:
    #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
     
  4. macrumors 603

    Joined:
    Aug 9, 2009
    #4
    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:
    Code:
    #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.
     

Share This Page