I wrote a translator, that reads a DIMACS graph format and writes to a simpler format...
basically DIMACS format is:
this is the file im using:
the output i want is:
the code is this one:
in was opened with "r"
out was opened with "w+"
both were checked if null
ant it works well..
but for some reason, after writing a lot of edges it sends me a segmentation fault..
original file is:
in the output file i have:
thats not all of the original files edges, its like more than a half..
then SEGMENTATION FAULT.. and aborts
what could be happening? some kind of writing limit?
basically DIMACS format is:
Code:
c comment p type nodes edges //type is alwats edge on my problems, nodes is the number of nodes and edges number of edges e v1 v2 //this means an edge connecting v1 and v2, both integers
Code:
c FILE: miles500.col c Translated from Stanford GraphBase File: miles500.gb c Stanford GraphBase ID: miles(128,0,0,0,500,127,0) p edge 128 2340 e 1 120 e 1 110 ..... (many many many edges here) e 128 8 e 128 7
Code:
nodes edges v1 v2 ...
in was opened with "r"
out was opened with "w+"
both were checked if null
Code:
char line[400]; char* token; while( !feof(in)) { fgets(line, 399, in); if(line[0] == 'p') { int nodes, edges; strtok(line, " "); token = strtok(NULL, " "); token = strtok(NULL, " "); nodes = atoi(token); token = strtok(NULL, " "); edges = atoi(token); fprintf(out, "%d %d\n", nodes, edges); } else if(line[0] == 'e') { int v1, v2; strtok(line, " "); token = strtok(NULL, " "); v1 = atoi(token); token = strtok(NULL, " "); v2 = atoi(token); fprintf(out, "%d %d\n", v1, v2); } }
ant it works well..
but for some reason, after writing a lot of edges it sends me a segmentation fault..
original file is:
in the output file i have:
Code:
128 2340 1 120 1 110 1 109 ... keeps writing ok 111 84 111 75
then SEGMENTATION FAULT.. and aborts
what could be happening? some kind of writing limit?
Comment