Kendall Weihe
Kendall Weihe

Reputation: 111

Expecting ; at end of string declaration

What is wrong syntactically with these character arrays?

struct NewBuiltIn{
    char *CommandName[64] = "bigbluetest";
    char *FunctionName[64] = "big_blue_test";
    char *AnalyzerFunction[64] = "bbt_analyzer";
};

I get error code...

error: expected ';' at end of declaration list
        char *CommandName[64] = "bigbluetest";
                             ^
                             ;

Upvotes: 0

Views: 79

Answers (1)

Ryan
Ryan

Reputation: 14659

You can't initalize a struct at the time you are defining it. So you should define it proper, then create an instance of it.

struct NewBuiltIn my_builtin = {
    "bigbluetest",
    "big_blue_test",
    "bbt_analyzer"
};

So to define the struct, you can do it like this:

struct NewBuiltIn {
    char CommandName[64];
    char FunctionName[64];
    char AnalyzerFunction[64];
};

Which defines a struct NewBultIn with 3 members, all of which are char arrays. Your definition was creating an array of char * pointers.

Upvotes: 1

Related Questions