I've been stuck on this for weeks trying getline, read, seemingly everything. It's ridiculous :P
So can someone please answer me, in the following code, how would I make it so buffer is equal to the data inside the text file opened by fin.open()?
1 2 3 4 5 6 7 8 9 10 11 12
various declarations
usingnamespace std;
int main
{
char* buffer;
int last;
fin.open(Parent_file.c_str());
last = ceil(end);
//here I need buffer = the text document.
fin.close();
pause();
}
i need to do that because the rest of the code works very very nicely when buffer is equal to a string of text (sounds cliche and obvious but hey). I've tested it using buffer = "whatever example text i want." and made everything work out nicely.
The program is actually going to be used for splitting up a text file into sets of 4kb. Like I said, i've gotten everything very nicely worked out up until this part. Why 4kb? Because i want to read books on my iPod.
sooooo.... any ideas on how i could make buffer equal the text in the document?
//size is the length of the text
buffer = newchar[size]; //or size+1 so it ends with '\0'
fin.read(buffer, sizeof(char)*size); //fin must be open in binary mode
Or read line by line, and append with a '\n' character
I've been stuck on this for weeks trying getline, read, seemingly everything. It's ridiculous :P
ne555, i've tried read, i've tried that code. It doesn't work. In this case it's returning a buffer not being initialized error. that was a pch issue, my bad. In this case it's storing not storing anything though.
How can I do it without the file being in binary mode?
That's kind of really hard to do, as each variable is stored and used in each part of the program. But here, i've attached a full copy of the cpp file and header.
interesting. well, considering this still isn't working, even though i implemented what you said, i think i'll worry more about this than that for now. Buffer still isn't storing anything at all for me.