PDA

View Full Version : Writing to a file



ImpactDNI
01-06-2003, 10:40 AM
Alright, i imported verticies, faces, and normals from a .ase file, and now i want to spit them out into my own (.dan) file... but, when its writing the normals to the file, it stops early... for no reason... it just stops writing... like, in the middle of a line... I have a for() loop to get thru all the normals (in a class)... and then when it gets to like the last 1.. it displays only the x,y coords, no z.... but if i stop it sooner, it just writes part of the next line... should be "misslemodel (missle)". It only writes "misslemod".. but the part where it writes that line, is all in one fprintf() line...
Any ideas? Can windows only write so much, or so many chars to a .txt file? (.dan)??
Thanks in advance,
Dan Sherman

jebus
01-06-2003, 10:44 AM
post some code. w/out seeing your code, no one can really help you.

jebus

ImpactDNI
01-06-2003, 04:17 PM
Sorry, at home right now, code at school... it'll be up tomorrow... Check back for me?

ImpactDNI
01-07-2003, 09:45 AM
fprintf(s, "#ifndef vect1\ntypedef float vect1;\n#endif\n\n#ifndef vect3\ntypedef vect1 vect3[3];\n#endif\n\n#ifndef triangle\ntypedef vect1 triangle[3];\n#endif\n\n");
fprintf(s, "#ifndef %smodel\ntypedef struct\n{\n", mn);
fprintf(s, "\tvect3 verticies[%i] = {\n\t", p->numVertex);
for (int a=0; a<(p->numVertex-1); a++){
fprintf(s, "{%f,%f,%f}, ", p->verts[a][0], p->verts[a][1], p->verts[a][2]);
if (a%2 == 0){
fprintf(s, "\n\t");
}
}
fprintf(s, "{%f,%f,%f}};\n", p->verts[p->numVertex-1][0], p->verts[p->numVertex-1][1], p->verts[p->numVertex-1][2]);

fprintf(s, "\ttriangle faces[%i] = {\n\t", p->numFaces);
for (a=0; a<(p->numFaces-1); a++){
fprintf(s, "{%i,%i,%i}, ", p->faces[a].vertIndex[0], p->faces[a].vertIndex[1], p->faces[a].vertIndex[2]);
if (a%2 == 0){
fprintf(s, "\n\t");
}
}
fprintf(s, "{%i,%i,%i}};\n", p->faces[p->numFaces-1].vertIndex[0], p->faces[p->numFaces-1].vertIndex[1], p->faces[p->numFaces-1].vertIndex[2]);

fprintf(s, "\tvect3 facenormal[%i] = {\n\t", p->numFaces);
for (a=0; a<(p->numFaces-14); a++){
fprintf(s, "{%f,%f,%f}, ", p->faces[a].normal[0][0], p->faces[a].normal[0][1], p->faces[a].normal[0][2]);
if (a%2 == 0){
fprintf(s, "\n\t");
}
}

the output from this section looks like this (importing a cube from .ase)
OK, WTF, i run my program on a huge .ase file, and the above happens... i run it on a cube... and it exports NOTHING, absolutly NOTHING...

ImpactDNI
01-07-2003, 09:47 AM
wierd, after bugging around with it... my order of opps is
Read in;
Export to file;
display model;
If i take out the Displaying.. it runs fine, and exports everything...
but if i leave in the displaying... it stops short on the exporting.. even though the whole export function is called before the display is ever even mentioned...

jebus
01-07-2003, 10:14 AM
are you flushing your buffer and closing the file before you display? do you need the file open for some reason after you've written it?

jebus

ImpactDNI
01-07-2003, 10:39 AM
Aha, never closed the file... that prolly has something to do with it...
Lol, just leaving school now... ill do it tomorrow.. thanks a ton man!