I am having trouble allocating nodes for my graph. Here are my structures defined in my header:
typedef struct Graph {
struct Node** _node_list;
int _sz;
} Graph;
typedef struct Node {
char *code;
char **_outgoing_arcs;
int _sz;
} Node;
and here are my allocation functions:
Graph* allocGraph(int sz)
{
Graph *g;
g = malloc(1000);
g->_sz = 0;
return g;
}
Node* allocNode(char *c, Graph *g)
{
Node *n;
n = malloc(1000);
strncpy(n->code,c,3);
g->_node_list[g->_sz] = n;
g->_sz += 1;
return n;
}
I can allocate graphs just fine, but when I try to allocate nodes my program crashes. Did I not do strncpy correctly? It always takes input of strings 3 long "ABC", "FOO" ...