结构数组

时间:2011-03-01 01:42:01

标签: c arrays struct

尝试创建一个结构数组(C的新用户),但是当我尝试初始化数组时,我得到的是“数组类型具有不完整的元素类型”。我做错了什么?

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 个答案:

答案 0 :(得分:8)

您已定义类型struct morsecharMorseChar,但您尝试使用未定义的类型struct MorseChar。相反,写

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