Note that there are some explanatory texts on larger screens.

plurals
  1. POExtra edge in my list?
    primarykey
    data
    text
    <p>I'm writing code to create a matrix out of a list of edges.</p> <p>However, when I run said code, I get a "phantom edge" that is not in the input data, which goes on to screw up the rest of my program. The edge is 9,2 in the matrix, or 8,1 in elemental code form.</p> <p>All elements in the matrix are initialized to 0 before hand.</p> <p>Here is the input data to do with the matrix:</p> <pre><code>1 2 1 8 2 8 3 5 3 1 4 5 4 6 5 2 5 9 6 4 6 8 7 4 7 10 8 4 8 6 9 4 9 5 10 7 10 3 </code></pre> <p>Here are the functions that handle the input:</p> <pre><code>void displayMatrix(int **matrix, int numberVertices){ //function displays the matrix int i, j; for(i=0; i&lt;numberVertices; i++) //go through eveyr element { for(j=0; j&lt;numberVertices; j++) { printf("%d ", matrix[i][j]); //print element } printf("\n"); } printf("\n\n"); } void inputMatrix(FILE *fp, int ** matrix) //file places value 1 into matrix if edge exists for the adjacency matrix { int e1, e2; while(!feof(fp)) //continue to the end of the file { fscanf(fp, "%d %d", &amp;e1, &amp;e2); //get pairs e1 = e1 - 1; //adjust the edges for array use e2 = e2 - 1; matrix[e1][e2] = 1; //place value 1 into appropriate location in adjacency matrix } fclose(fp); //close the file connection } 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 *1 0 1 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 </code></pre> <p>*the entry that should not exist, not in the input data</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload