delete last character in file

hello wrote a simple keylogger in c + + backspace button, I would like to work in such a way that after you click opens the file are stored into the characters from the keyboard and removes the last character from a file
how to do?
How to delete the last character from a text file without knowing the number of characters in a file
If you don't had spoken that is a keylogger program, someone could help you, next time, remember this :D.

Majority of people not like of keyloggers, but don't remember that NSA have software beyond it for spy on them :D

Embrace.
To delete last character of a text file, can you not just truncate the file by size of 1?
How can truncate the file size -1? byte
Last edited on
To delete last character of a text file, can you not just truncate the file by size of 1?

Don't do that. If for no other reason then you are making random guesses about the file format.


How to delete the last character from a text file without knowing the number of characters in a file(?)

The answer to this is to simply find the number of characters in the text file. There is no scenario where you would be able to open a file but you wouldn't be able to enumerate the contents.
Don't do that. If for no other reason then you are making random guesses about the file format.


if you have created the keylogger which writes to this text file then you are not making random guesses about structure of the file.

How can truncate the file size -1? byte


try using the [_chsize] function.

I also wondered why you needed to remove last character from file but considered it may be part of your application logic like not wanting to persist the last exiting character ... what are your reasons?
if you have created the key logger which writes to this text file then you are not making random guesses about structure of the file.

That was actually directed at you... Sorry for not making that clear. It's an honest mistake to just assume that someone who is writing in English is using standard ASCII, but the OP didn't mention whether he was using Unicode or Multi-byte. Where as with my solution it becomes a non-issue.
but the OP didn't mention whether he was using Unicode or Multi-byte


MBCS are legacy and thus don't expect OP to be writing a key logger to support that.

Given the two choices left, unicode or ascii, I would know which one I'm dealing with and truncate file accordingly:

for ascii i will truncate by 1 byte.
for unicode i will truncate by 2 bytes due to each character being 16 bits in unicode.
Topic archived. No new replies allowed.