简体   繁体   中英

Array of structs

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', "----."},
                            {'.', "#"},     {'-', "^"}}; 

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 */ };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM