How do i load a whole file in to an array?
How do i load a whole file in to an array?
I didn't even need to read the post, your thread subject told me EVERYTHING I needed to know about your problem.Probs
Read the rules and post properly next time.
Look up the ReadFile() function.How do i load a whole file in to an array?
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
How do you want your array set up? You could have every element of the array be a character, a line, or a paragraph. You could even have something else depending on how your file is formatted. You need to be a helluva lot more specific. Posting code would be very helpful.
FAQ
"The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.
"If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.
i'm assuming your data file is set up the way i have mine for the battle system... in that case...just modify that to fit your needsCode:ifstream infile("stats.dat"); //open stats file while(infile.getline(filename,20,' ')) //while more usernames, take it in { if(!strcmpi(filename,username)) //if filename matches { if(debug) { cout<<username<<"::"<<filename<<endl; //test string system("pause"); //test pause } infile.ignore(100,'h'); //ignore password field infile>>hp>>null>>atk>>null>>def>>null>>lvl>>null>>exp>>null >>mon>>null>>points; break; //end loop } else infile.ignore(1000,'\n'); //ignore rest of line } infile.close(); //close file
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
Here is some code I've used before to read in a file into an array...maybe you'll find it usefull somehow:
Code:void readFromInputFile( char *text, // large array to store input text long &index, // number of input file characters char fileName[])// filename to use for input { ifstream inStream; // Input file stream ofstream outStream; // Output file stream // Set value of index to start at 0, in case we're calling this function a second time index = 0; // open input file inStream.open(fileName); // associate the actual file name with "inStream" if ( inStream.fail() ) { cout << "Input file opening for " << fileName << " failed.\n" << "The file either doesn't exist or is not in the current directory.\n" << "Exiting...\n\n" << endl; exit(-1); } /* // open output file for debugging purposes outStream.open("output.txt"); // associate the actual file name with "inStream" if ( outStream.fail() ) { cout << "Output file opening for output.txt failed.\n" << "The file either doesn't exist or is not in the current directory.\n" << "Exiting...\n\n" << endl; exit(-1); } */ // Read in the characters into our big array while ( inStream.get(text[ index++]) ) { if ( index >= MaxSize) { cout << "MaxSize of " << MaxSize << " was reached.\n"; break; } // outStream << text[ index-1]; // for debugging } // close the input file inStream.close(); }
some entropy with that sink? entropysink.com
there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka