Deleting a character in a text file
-
i want to know how to delete a character in a text file. if i use '\b' or ascii 127(del), then i get some special characters in my file instead the characters getting deleted. Probably windows doesnt recoznise these characters as dos does. Is there any other way or any other character that can be used to delete charactes in a file either backwards or forwards ??? I use visual studio.net as my compiler. Pls hlp. Nikhil
-
i want to know how to delete a character in a text file. if i use '\b' or ascii 127(del), then i get some special characters in my file instead the characters getting deleted. Probably windows doesnt recoznise these characters as dos does. Is there any other way or any other character that can be used to delete charactes in a file either backwards or forwards ??? I use visual studio.net as my compiler. Pls hlp. Nikhil
- Open (for read/write) the file read it into a CString or std:string, find the character you want to delete and then use the appropriate function call to delete it from the string, finaly move to the beginning of the file and write the string back to the file. 2) You could also just allocate a buffer larg enought to hold the entire file (+1, buffer must end w/NULL), read the data into the buffer, find the character, then use memmove function to delete it, finaly writing back to the file. 3) You could also read it into a large buffer then write it back to the file while skip the character that you want deleted. 4) (worst way of all - this is realy bad) Open a tempory file and the origanal, read 1 character at a time from the origanal file and write it to the tempory file, when you find the character you want to delete then just do not copy it to the temporay file. Once you reach the end of the file you could copy the tempory file back to the origanal (or delete the origanal and rename the temporary with the origanal name). Use your imagination, there are more ways to skin this cat than I count. But one way that you cann't do it is by inserting anouther character into the data stream. Good Luck! INTP