Array of Structures

Trying to create an array of structures (new to C), but I get an "array type has an incomplete element type" when I try to initialize an array. What am I doing wrong?

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', "----."},
                            {'.', "#"},     {'-', "^"}}; 
+3
source share
1 answer

You have defined the types struct morsecharand MorseChar, but you are trying to use the type undefined struct morsechar. Write instead

MorseChar lookup[] = { /* Same as before */ };
+8
source

Source: https://habr.com/ru/post/1795377/


All Articles