У меня проблема с добавлением элемента (структуры) в динамический массив, который находится в структуре.
Здесь основная структура
struct testfw_t
{
char* program;
int timeout;
char *logfile;
char *cmd;
bool silent;
bool verbose;
struct testTab *tests;
};
Здесь массив
struct testTab
{
int size;
struct test_t *oneTest;
};
и, наконец, добавляемый элемент:
struct test_t
{
char *suite; /**< suite name */
char *name; /**< test name */
testfw_func_t func; /**< test function */
};
Так что мне нужно добавить struct test_t
в массив testTab
в struct testfw_t
, и я потерян во многомиз malloc
и realloc
вызовов.
PS: инициализация основной структуры, если она может быть полезной, которая работает:
struct testfw_t *testfw_init(char *program, int timeout, char *logfile, char *cmd, bool silent, bool verbose){
struct testfw_t *t;
t = malloc(sizeof(struct testfw_t));
t->program = program;
t->timeout = timeout;
t->logfile = logfile;
t->cmd = cmd;
t->silent = silent;
t->verbose = verbose;
t->tests = malloc(sizeof(struct testTab));
t->tests->size=0;
t->tests->oneTest=NULL;
return t;
}
РЕДАКТИРОВАТЬ: Что я пытаюсь
struct test_t *nouveau;
nouveau->suite = suite;
nouveau->name = name;
nouveau->func=func;
//fw->tests=realloc(fw->tests->oneTest,(fw->tests->size+1) * sizeof(struct testTab));
fw->tests->oneTest=malloc((fw->tests->size+1) * sizeof(nouveau));
fw->tests->oneTest[fw->tests->size+1] = *nouveau;
fw->tests->size++;
return nouveau;