Archived

This topic is now archived and is closed to further replies.

CoolMike

file reading

Recommended Posts

I am trying to write a function that will simply read a list of names out of a text file and place them into an array. It all seems to work fine when I put the following function in my game, but the game crashes as soon as it is finished. The function does finish though, and I want to know if anyone else could look at this and see why it still crashes. Thanks in advance, Mike //GLOBALS & DEFINES #define num_names 64 char names[num_names][32]; //THE LOADING FUNCTION void loadNames(char *text) { char c; int i, //i = counts through each name j; //j = counts through each ASCII symbol/letter bool nextName = false, eoffound = false; FILE *stream, *debugFile; stream = fopen( text, "r+" ); debugFile = fopen( "debug.txt", "w+" ); fseek( stream, 0, SEEK_SET ); fseek( debugFile, 0, SEEK_SET ); for(i=0; i[j] = c; //*_strlwr(&c); j++; //print debug info to file if(c==''\n'') fprintf( debugFile, "\n"); else if(eoffound==true) fprintf( debugFile, "*"); else fprintf( debugFile, "%c", c); } if(eoffound==true) break; nextName = false; } fclose( stream ); fclose( debugFile ); } ---------------------- The "stars.txt" file is just a list of names. Just copy and paste the list into notepad and save as "stars.txt". stars.txt ---------------------- Sol Alpha Centauri Orion Telos Siat Mantago San Soven PRX 790 Mutaba ----------------------

Share this post


Link to post
Share on other sites
Okay, I assume you have tried this in another program to test it, yes ?
If you haven''t then it would be a good idea.
It seems to be in order, from a quick look.

FYI, I always use the fstream set of commands with file stuff- its reasonably easy.
~V''lion



I came, I saw, I got programmers block.
~V''''lion

Share this post


Link to post
Share on other sites