I'm trying to make an array of dynamic structs in C, however I'm not understanding why it's returning me segmentation fault.
The code is basically this:
I'm just creating a vector of 10 arrays and then trying to initialize each struct individually, can anyone help me?
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#define MAX_NODES 10000
#define INF 999999999
typedef struct Node{
int value;
int listaAdj[MAX_NODES];
int pesoArestas[MAX_NODES];
int visited;
}Node;
//variaveis globais
Node *grafo;
int numVertices = 10;
int main(){
int i,j;
grafo = (Node*) malloc((numVertices) * sizeof(struct Node*));
for ( i = 0; i < numVertices; i++ ){
if ( i == 0 ){
grafo[i].value = 0;
}else{
grafo[i].value = INF;
}
for ( j = 0; j < MAX_NODES; j++ ){
grafo[i].listaAdj[j] = -1;
grafo[i].pesoArestas[j] = -1;
}
grafo[i].visited = 0;
}
for ( i = 0; i < numVertices; i++ ){
printf(" %d \n", grafo[i].value);
}
free(grafo);
return 0;
}