gpt4 book ai didi

复杂数组初始化

转载 作者:行者123 更新时间:2023-11-30 20:51:58 29 4
gpt4 key购买 nike

有人可以解释一下为什么会出现此错误以及在我的情况下应该如何完成复杂的数组初始化?

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 #

最佳答案

上线

{"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

关于复杂数组初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22961659/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com