I have a quick question about recording a backspace character in an opened file.
Now I have searched for a couple of hours and figured out that in order to accurately record a backspace character within C++ inside of a "notepad" file, I would need to somehow open instead of a static file, but a temporary file and than have a condition when the backspace character is pressed, to go delete a single key that was stored in the buffer of the temporary file, and than to have the temporary file copy itself and save itself as a static file.
I just wanted to know if this was correct, and if it is, how could I possibly turn the temporary file into a static file for ones to open and view what they typed.
In basic terms I am coding a notepad program and trying to accurately convey that backspace character. But I am having a hard time understanding the opening of a temporary file, the recording of the backspace character through pointers, AND THAN saving it as a static file.
What do you mean record a backspace character in a file? Backspace presses usually happen at runtime, and there you would operate on the buffer, deleting the last character that was entered. So a backspace character would usually never end up in a text file in the first place.
Well in order to clear a character or string of charcters inside of a file using the backspace key, I thought that only works when a temporary file is open because you can not delete already "posted" data thats inside of a file.
Many others uggest fseek() but I feel that having to worry about the position of the cursor will be even more of a hassle than just trying to delete data already in a buffer.
Someone suggested that You can only alter the values of bytes in-place. If you want to remove or insert bytes from a file, you have to either buffer a bunch of data in memory, or use a temporary file. Basic idea:
while not end of file:
read bytes from input
alter the bytes and write them to the output (a NEW file)
end while
Well, that is true, but when working with files you usually work with memory, and only save the file when you're actually done (which means, when working with a text file you have the whole text - or the part of the text you are currently working with - in memory, when a backspace is entered you remove a character from that text object. You only save the file at the end of the session). There may be exceptions, but that's how you usually deal with text files at least.
Ahh ok I understand that sot he temporary file idea is a bust.
So my friend suggested that I just use console buffer in order to actually produce the effect of backspace key.
The whole concept about buffers sorta slips past my understanding as of now, so is there any recommendations you can offer to me about using console buffer in order to delete data when backspace character is pressed?