2014-04-09 87 views
-4

有人可以解釋我爲什麼有這個錯誤,在我的情況下應該如何完成複雜的數組初始化?複雜的數組初始化

z3 srC# head -37 company.c 
#include <stdio.h> 
#include <errno.h> 
#include <stdlib.h> 
#include "company.h" 
#include "mytypes.h" 
#include "depserv.h" 
#include "table_defs/t_cat_deptype.h" 

#define NUM_DEFAULT_DEPTYPES   9 
typedef struct itl_cat_deptypes_t { 
     t_cat_deptype_t   deptypes[NUM_DEFAULT_DEPTYPES]; 
} itl_cat_deptypes_t; 

itl_cat_deptypes_t cat_deptypes[2] = { 
     { 
       {"Information Request",'\0'}, 
       {"Question",'\0'}, 
       {"Meeting",'\0'}, 
       {"Event",'\0'}, 
       {"Task",'\0'}, 
       {"Objective/Goal",'\0'}, 
       {"Authorization Request",'\0'}, 
       {"Dependency",'\0'}, 
       {"Custom",'\0'} 
     },{ 
       {"Solicitud de Informacion",'\0'}, 
       {"Pregunta",'\0'}, 
       {"Junta",'\0'}, 
       {"Evento",'\0'}, 
       {"Tarea",'\0'}, 
       {"Objetivo/Meta",'\0'}, 
       {"Solicitud de Autorizacion",'\0'}, 
       {"Dependencia",'\0'}, 
       {"Personalizado",'\0'} 
     } 
}; 

z3 srC# head table_defs/t_cat_deptype.h 
#ifndef _T_CAT_DEPTYPE_ 
#define _T_CAT_DEPTYPE_ 

typedef struct t_cat_deptype_t { 
     char       description[64]; 
     char       inactive; 
} t_cat_deptype_t; 

#endif 

z3 srC# make company.o 
gcc -ggdb -Wmissing-prototypes -Wmissing-declarations -Wunused -Winline -Wno-format  -Wstrict-prototypes -Wimplicit-function-declaration -fmax-errors=5 -D_GNU_SOURCE -I./table_defs -c company.c 
cc1: warning: command line option "-fmax-errors=5" is valid for Fortran but not for C 
company.c:17:3: error: extra brace group at end of initializer 
company.c:17:3: error: (near initialization for 'cat_deptypes[0]') 
company.c:17:3: warning: excess elements in struct initializer 
company.c:17:3: warning: (near initialization for 'cat_deptypes[0]') 
company.c:18:3: error: extra brace group at end of initializer 
company.c:18:3: error: (near initialization for 'cat_deptypes[0]') 
company.c:18:3: warning: excess elements in struct initializer 
company.c:18:3: warning: (near initialization for 'cat_deptypes[0]') 
company.c:19:3: error: extra brace group at end of initializer 
company.c:19:3: error: (near initialization for 'cat_deptypes[0]') 
company.c:19:3: warning: excess elements in struct initializer 
company.c:19:3: warning: (near initialization for 'cat_deptypes[0]') 
company.c:20:3: error: extra brace group at end of initializer 
company.c:20:3: error: (near initialization for 'cat_deptypes[0]') 
company.c:20:3: warning: excess elements in struct initializer 
company.c:20:3: warning: (near initialization for 'cat_deptypes[0]') 
company.c:21:3: error: extra brace group at end of initializer 
company.c:21:3: error: (near initialization for 'cat_deptypes[0]') 
company.c:21:3: warning: excess elements in struct initializer 
company.c:21:3: warning: (near initialization for 'cat_deptypes[0]') 
company.c:22:3: error: extra brace group at end of initializer 
company.c:22:3: error: (near initialization for 'cat_deptypes[0]') 
company.c:22:3: warning: excess elements in struct initializer 
company.c:22:3: warning: (near initialization for 'cat_deptypes[0]') 
company.c:23:3: error: extra brace group at end of initializer 
company.c:23:3: error: (near initialization for 'cat_deptypes[0]') 
company.c:23:3: warning: excess elements in struct initializer 
company.c:23:3: warning: (near initialization for 'cat_deptypes[0]') 
company.c:24:3: error: extra brace group at end of initializer 
company.c:24:3: error: (near initialization for 'cat_deptypes[0]') 
company.c:24:3: warning: excess elements in struct initializer 
company.c:24:3: warning: (near initialization for 'cat_deptypes[0]') 
company.c:27:3: error: extra brace group at end of initializer 
company.c:27:3: error: (near initialization for 'cat_deptypes[1]') 
company.c:27:3: warning: excess elements in struct initializer 
company.c:27:3: warning: (near initialization for 'cat_deptypes[1]') 
company.c:27:20: error: expected '}' before '.' token 
make: *** [company.o] Error 1 
z3 srC# 
+0

什麼是't_cat_deptype_t'? –

+0

@MichaelWalz我在這個問題中描述了它,請重新閱讀 – Nulik

+0

不,你沒有描述它,它是在'table_defs/t_cat_deptype.h'中定義的,我無法猜測該文件中的內容。 –

回答

3

在線路

{"Pregunta",'\0'}. 

itl_cat_deptypes_t cat_deptypes[2] = { 
     { 
       {"Information Request",'\0'}, 
       {"Question",'\0'}, 
       {"Meeting",'\0'}, 
       {"Event",'\0'}, 
       {"Task",'\0'}, 
       {"Objective/Goal",'\0'}, 
       {"Authorization Request",'\0'}, 
       {"Dependency",'\0'}, 
       {"Custom",'\0'} 
     },{ 
       {"Solicitud de Informacion",'\0'}, 
       {"Pregunta",'\0'}. 
       {"Junta",'\0'}, 
       {"Evento",'\0'}, 
       {"Tarea",'\0'}, 
       {"Objetivo/Meta",'\0'}, 
       {"Solicitud de Autorizacion",'\0'}, 
       {"Dependencia",'\0'}, 
       {"Personalizado",'\0'} 
     } 
}; 

有一個.代替,在該行的末尾。這也是編譯器告訴你的:

company.c:27:20: error: expected '}' before '.' token 
+0

這不是錯誤的原因,改變了' 「。按','你會看到。此外,編譯器會從第17行生成錯誤,而不是第27行。 – Nulik

+0

編譯器告訴您它從第17行開始,從第17行開始初始化數組。如果你仔細觀察,它會一直走到遇到錯誤的那一行。我向你展示的是哪條線。 – ThaMe90

+0

@ TheMe90您指出的錯字與編譯器錯誤沒有關係,如果將其刪除,則會出現相同的錯誤。你只是回答得分,但爲了幫助我解決問題,爲此付出了努力。 – Nulik