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 开发者_JAVA百科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 */ };
精彩评论