3

Trying to create an array of structs (new to C), but I am getting a "array type has incomplete element type" when I try to initialize the array. What am I doing incorrectly?

typedef struct morsechar
{
   char  character;
   char* morse;
} MorseChar;

struct MorseChar lookup[] ={{'A', ".-"},    {'B', "-..."},  {'C', "-.-."},  
                            {'D', "-.."},   {'E', "."},     {'F', "..-."},      
                            {'G', "--."},   {'H', "...."},  {'I', ".."},
                            {'J', ".---"},  {'K', "-.-"},   {'L', ".-.."},
                            {'M', "--"},    {'N', "-."},    {'O', "---"},
                            {'P', ".--."},  {'Q', "--.-"},  {'R', ".-."},
                            {'S', "..."},   {'T', "-"},     {'U', "..-"},
                            {'V', "...-"},  {'W', ".--"},   {'X', "-..-"},
                            {'Y', "-.--"},  {'Z', "--.."},  {'0', "-----"}, 
                            {'1', ".----"}, {'2', "..---"}, {'3', "...--"},
                            {'4', "....-"}, {'5', "....."}, {'6', "-...."},    
                            {'7', "--..."}, {'8', "---.."}, {'9', "----."},
                            {'.', "#"},     {'-', "^"}}; 

1 Answer 1

8

You have defined types struct morsechar and MorseChar, but you are trying to use the undefined type struct MorseChar. Instead, write

MorseChar lookup[] = { /* Same as before */ };
Sign up to request clarification or add additional context in comments.

3 Comments

or struct morsechar but then the typedef would be superfluous. +1.
Thanks for the reply, but with that correction I am still getting the same error: array type has incomplete element type
@Cory Also it's not necessary to specify a struct tag when using a typedef unless it's a recursive structure: typedef struct { ... } MorseChar; is sufficient.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.