Iv'e written a function to save some strings and floats (function parameters to be loaded later) to simple ASCII file. The variables are written to the file, based on data in an array, accessed with a for loop.
To write the strings, i'm using strncpy to copy the values into temporary variables, so I can keep everything at a consistant size.
However, when it saves, it saves so that the the string variables don't seem to change..tmptex0 writes the same thing over and over.
Anyway, the question is, what's the problem here, and how can it be solved?Code:void level::save(char *fname) { stream = fopen(fname, "w+"); fseek(stream, 0L, SEEK_SET); fprintf(stream, "%ld\n", VERSION); //prefabs fprintf(stream, "%d\n", num_prefabs); for(int i=0; i<num_prefabs; i++) { strncpy(tmptex0, prefabP[i].strtexture0, sizeof(GLUI_String)); strncpy(tmptex1, prefabP[i].strtexture1, sizeof(GLUI_String)); if(prefabP[i].type==0) fprintf(stream, "%ld %s %s %d %f %f %f %f %f %f\n", SOLIDCUBE, tmptex0, tmptex1, prefabP[i].textype, prefabP[i].pos.x, prefabP[i].pos.y, prefabP[i].pos.z, prefabP[i].scale.x, prefabP[i].scale.z, prefabP[i].scale.y); } //entities fprintf(stream, "%d\n", num_meshs); for(i=0; i<num_meshs; i++) { strncpy(tmptex0, meshP[i].tex1, sizeof(GLUI_String)); strncpy(tmptex1, meshP[i].tex2, sizeof(GLUI_String)); strncpy(tmpfname, meshP[i].filename, sizeof(GLUI_String)); fprintf(stream, "%ld %s %s %s %d %f %f %f %f %f %f\n", STATICMESH, tmpfname, tmptex0, tmptex1, meshP[i].textype, meshP[i].pos.x, meshP[i].pos.y, meshP[i].pos.z, meshP[i].scale.x, meshP[i].scale.z, meshP[i].scale.y); } fclose(stream); }
-psychopath



LinkBack URL
About LinkBacks



