Resolved "Expected identifier" error when using C code

Discussion in 'iOS Programming' started by moonman239, Jan 22, 2014.

  1. moonman239, Jan 22, 2014
    Last edited: Jan 23, 2014

    moonman239 macrumors 68000

    Joined:
    Mar 27, 2009
    #1
    The following problem has been solved. Below the second code block is a quote from the post that helped me most.

    I am using the PocketSphynx library. I chose not to install the Xcode binaries because it seems that to do so would require that I run autoconfig, which in turn would require that I download tools that I do not want to download.

    I have placed a C method inside the implementation file of a subclass of NSObject, but when I call that function inside an Objective-C method, I get the error I have mentioned.

    EDIT: Directly below this sentence is the line of code that is given me the error. This line is located in the relevant implementation block.
    Code:
    int pocketSphinxInitialized = [initializePocketSphinx()];
    Directly below this sentence is the code that is located in the implementation file that the above line is located in.
    Code:
    #import "PocketSphinx.h"
    #define MODELDIR "c:/sphinx/model"
    
    int initializePocketSphinx()
    {
        ps_decoder_t *ps;
        cmd_ln_t *config;
        
        config = cmd_ln_init(NULL, ps_args(), TRUE,
                             "-hmm", MODELDIR "/hmm/en_US/hub4wsj_sc_8k",
                             "-lm", MODELDIR "/lm/en/turtle.DMP",
                             "-dict", MODELDIR "/lm/en/turtle.dic",
                             NULL);
        if (config == NULL)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }
    
    @implementation PocketSphinx
    
    +(PocketSphinx *)initialize
    {
        PocketSphinx *pocketSphinx = [[PocketSphinx alloc] init];
        int pocketSphinxInitialized = [initializePocketSphinx()];
        return pocketSphinx;
    }
    @end
    
    The post that helped me most:
     
  2. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    Which line is giving you the error?

    Also, I'd replace your if ... return 1 else return 0 with just return config == NULL.
     
  3. mjohnson1212 macrumors member

    Joined:
    Nov 15, 2007
    #3
    You don't need the square brackets for a call to a C function.
     
  4. moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #4
    The following line, which is located in the implementation block.

    Code:
    int pocketSphinxInitialized = [initializePocketSphinx()];
    Also, thank you for the advice.
     
  5. moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #5
    I just did what you suggested, then the error went away. Thank you!
     

Share This Page