i wrote this program and what i want it to do is
copy all the data from the Memblock and put it into the DelDupTemp except for the letter that was last entered
like this:
user inputs: xyzy
program outputs to file:xzy
the actual program output is like this
xzzy
this is because when i put the information from the DelDupTemp array into the file since DelDupTemp is smaller then Memblock one of the letters from Memblock is left over
i can't get anything to work
someone please help
is their a way to make it so the DelDupTemp will replace the Memblock completely?
void AI::SaveInput()
{
//create first memory block
char * TempMemblock;
//when ever the user inputs a character
//the size of the memory block is increased
//create a memory block
//save the data to it
std::ofstream file("data.bin", std::ios::out | std::ios::app | std::ios::ate | std::ios::binary);
TempMemblock = newchar;
*TempMemblock = *pCurrentChar;
file.write(TempMemblock, 1);
delete TempMemblock;
std::cout << "letter written to file" << std::endl;
file.close();
}
I have a couple questions.
1. Do you really need to use a file? I mean, is that part of the requirements, or is this just a workaround for something you don't know how to do?
2. Ignoring the fact that AI::SaveInput() is opening a file to write a single byte to it, what's the point of TempMemblock?
Do you need to keep the file updated at all times? Reading and writing to the same file without closing all streams that use it is rather messy, and more often than not an unnecessary complication. If you don't need to, it'd be better to keep the keystrokes in a structure of some sort and dump them all at once later. That's not only more organized, but also much, much faster than writing one byte at a time.