0
Hello. I am doing a job I read a txt (the file name is passed by argv[]) and I write a graph. In the first line of the file two parameters are passed as follows: V A These parameters are integers and have a meaning: V = number of vertices, A = number of edges. So far, beauty, I can get these numbers. The problem is to throw these numbers in the size of the two-dimensional array of struct floats. It needs to be something like "adj[numeroVertices][numeroVertices]".
typedef struct Grafo{
int numeroArestas;
int numeroVertices;
float **adj;
} Grafo;
int main(int argc, char *argv[]) {
int numVertices, numArestas;
FILE *f;
f = fopen(argv[1], "r");
fscanf(f, " %i %i", &numVertices, &numArestas);
Grafo g;
g.numeroArestas = numArestas;
g.numeroVertices = numVertices;
// g.adj = ???????
...
}
Thanks! Just one question: on this line "adj[k] = malloc(numArestas * size of **adj)" am I making it a square array? That is, if I pass a Vertices = 4, at the end of the for I will have a 4x4 array?
– Victor
You can use the final object as if it were a 4x4 array (but it is not a true array). In that part of the
/* usa adj como um array */
you can put anything like that:for (k = 0; k < 4; k++) { adj[k][0] = 0.8; adj[k][1] = -3.14; adj[k][2] = adj[k][3] = 0; }
– pmg