Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The format is similar to .obj format, which is not too hard to parse. You had it pretty good; your errors are mostly just typos at this point.</p> <p>Just use data in-place instead of pointers:</p> <pre><code>Vertex *vert[4]; </code></pre> <p>becomes:</p> <pre><code>Vertex vert[4]; </code></pre> <p>You'll also need to change all of your '->' notations to dot (.) notation, e.g:</p> <pre><code> tetrahedron[n].vert[0]=vert_std[ tetrahedron[n].vertid[0] ]; // retriving coords from the standard file and storing tetrahedron[n].vert[1]=vert_std[ tetrahedron[n].vertid[1] ]; // them in the vertex pointer array of tretrahedron tetrahedron[n].vert[2]=vert_std[ tetrahedron[n].vertid[2] ]; tetrahedron[n].vert[3]=vert_std[ tetrahedron[n].vertid[3] ]; </code></pre> <p>and your testing code should bring n back down one (it's currently lastLine+1):</p> <pre><code> // printing 13 variables in total... n--; // n must be last entry </code></pre> <p>Finally, I got a compile error on your allocations, and had to type cast them:</p> <pre><code>Vertex *vert_dt = (Vertex*) malloc( MAX * sizeof (Vertex) ) ; Vertex *vert_std = (Vertex*) malloc( MAX * sizeof (Vertex) ) ; Tetra *tetrahedron = (Tetra*) malloc(MAX * sizeof (Tetra) ); </code></pre> <p>Note that fscanf() is pretty strict, so an input file with, say, extra leading spaces might confuse the program. I tested these changes on made-up files, so no guarantees.</p> <p>Hope this helps! Here's my full file:</p> <pre><code>#define FILEPATHtri "grid1DT.txt" #define FILEPATHorg "grid1.txt" #define MAX 10000 #include &lt;assert.h&gt; #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include "math.h" typedef struct { float x; float y; float z; char ID; }Vertex; /* NOT USED ATM typedef struct { edge_ref next[4]; // pointers to other edges (AQE data structure) void *data[4]; // pointers to endpoints of edge unsigned ID; // ID of edge }Edge; */ typedef struct { Vertex vert[4]; int vertid[4]; char t; }Tetra; void file_link (void) { Vertex *vert_dt = (Vertex*) malloc( MAX * sizeof (Vertex) ) ; Vertex *vert_std = (Vertex*) malloc( MAX * sizeof (Vertex) ) ; Tetra *tetrahedron = (Tetra*) malloc(MAX * sizeof (Tetra) ); FILE *fp1,*fp2 ; fp1 = fopen( FILEPATHtri,"r"); int i = 0; while(fscanf(fp1, "%c %i %i %i %i ", &amp;tetrahedron[i].t, &amp;tetrahedron[i].vertid[0], &amp;tetrahedron[i].vertid[1], &amp;tetrahedron[i].vertid[2], &amp;tetrahedron[i].vertid[3] ) == 5 ) // Saving the line numbers into vertid[0..3] { i++; } fclose(fp1); fp2 = fopen( FILEPATHorg,"r"); int j = 0; while(fscanf(fp2, "%f %f %f ", &amp;vert_std[j].x, &amp;vert_std[j].y, &amp;vert_std[j].z ) == 3 ) { j++; } fclose(fp2); int n; for (n=0; n&lt;i; n++) { tetrahedron[n].vert[0]=vert_std[ tetrahedron[n].vertid[0] ]; // retriving coords from the standard file and storing tetrahedron[n].vert[1]=vert_std[ tetrahedron[n].vertid[1] ]; // them in the vertex pointer array of tretrahedron tetrahedron[n].vert[2]=vert_std[ tetrahedron[n].vertid[2] ]; tetrahedron[n].vert[3]=vert_std[ tetrahedron[n].vertid[3] ]; } int m = 100; //used to retrieve m'th tetra, so that I can print the tetra that I want,just for checking purposes.. // printing 13 variables in total... n--; // rewind to last tetrahedron printf("These are the 4 coordinates of the vertices of the %i th tetrahedron from the DT file %f %f %f\n%f %f %f\n%f %f %f\n%f %f %f\n", n, tetrahedron[n].vert[0].x,tetrahedron[n].vert[0].y,tetrahedron[n].vert[0].z, tetrahedron[n].vert[1].x,tetrahedron[n].vert[1].y,tetrahedron[n].vert[1].z, tetrahedron[n].vert[2].x,tetrahedron[n].vert[2].y,tetrahedron[n].vert[2].z, tetrahedron[n].vert[3].x,tetrahedron[n].vert[3].y,tetrahedron[n].vert[3].z); free(vert_dt); free(vert_std); free(tetrahedron); } int main(void) { file_link(); return 0; } </code></pre>
    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.
    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