edges = (struct edge *) malloc (sizeof(struct edge)*edges_num);
There is absolutely no need to cast the return value of malloc in C, and doing so can hide other issues, such as failing to #include...