rendered paste bodyvoid ReadGraph(struct graph *G, const char *filename)
{
FILE *fp;
char *s, *q, line[128];
long lval;
int nv, i, j;
struct edge *e;
fp = fopen(filename, "r");
if (!fp) {
printf("Den yparxei to arxeio %s\n", filename);
exit(2);
}
/* H prwth grammh einai o ari8mos twn kombwn */
s = fgets(line, 128, fp);
lval = strtol(s, 0, 10);
nv = (int) lval;
if (nv < 1 || nv > MAXVERTS) {
printf("Mh dekth timh gia ton ari8mo twn kombwn\n");
exit(2);
}
}
}
/* H prwth grammh einai o ari8mos twn kombwn */
s = fgets(line, 128, fp);
lval = strtol(s, 0, 10);
nv = (int) lval;
if (nv < 1 || nv > MAXVERTS) {
printf("Mh dekth timh gia ton ari8mo twn kombwn\n");
exit(2);
}
/*
* Ka8e mia apo tis epomenes nv grammes periexei tis akmes tou grafou
* kai to kostos metabashs apo ton ena kombo ston allo
*/
int A[nv][nv]; //O pinakas prosptosis!
for(i = 0; i < nv; i++)
A[i][i]=0;
for(i = 0; i < nv; i++){
G->firstedge[i] = 0;
A[i][i]=0;
for(i = 0; i < nv; i++){
G->firstedge[i] = 0;
s = fgets(line, 128, fp);
for(j=0; j<nv; j++){
lval=strtol(s, &q, 10);
if(q!=0){
e->endpoint = j;//telos akmis
e->cost = (int) lval;
e->next = G->firstedge[i];
G->firstedge[i] =e;
s = q;
}
}
}
G->nverts = nv;
}