I was creating some sort of text editing program.
Whose display and file writing are going parallely.

How to clear the character in the file when i dont back space.
I tried clear character by replacing with Space(32), NULL(0), but it didn't workout fine.. just replacing the character...how do delete the character.

//i tried it like this
fseek(fp,-1,SEEK_CUR);
fputc(<character to be replaced>,fp);
fseek(fp,-1,SEEK_CUR);

Usually you change the buffer in memory, then write the whole buffer to the file after all the changes are made. Don't try changing the file as you change the display.

Usually you change the buffer in memory, then write the whole buffer to the file after all the changes are made. Don't try changing the file as you change the display.

I know that stuff.. i if you try to do normally also it will store in buffer untill you don't flush it.. my question is i am clearing (deleting) character from the buffer what should i used to clear it.

I tried in many ways but eg. spaces (32), NULL(0) but its is also one of the character.

eg. "this is the file <space><space><space><eof>" which should be "this is the file<eof>" cosidering that i did backspacing from last only.
Please help!

No you can't do that.

Some platforms provide a specific "truncate" function to allow you to make a file shorter by removing stuff from the end.

But there is no API which allows you to turn say
hello world
into
goodbye world
in such a way that the file will automatically make room for the extra data.

In short, you have to rewrite the entire file from scratch each time.

Replacing text with other text which is the same length is possible, eg
hello world
into
howdy world
Indeed, this is how files with fixed-length records typically work.

No you can't do that.

Some platforms provide a specific "truncate" function to allow you to make a file shorter by removing stuff from the end.

But there is no API which allows you to turn say
hello world
into
goodbye world
in such a way that the file will automatically make room for the extra data.

In short, you have to rewrite the entire file from scratch each time.

Replacing text with other text which is the same length is possible, eg
hello world
into
howdy world
Indeed, this is how files with fixed-length records typically work.

i understand what you are saying and i am trying to write solve same problem which you mention making of "hello world" to "how is world".
But thats not what i want.. I want to know how to clear the character form the buffer.. at least from back side, so that it doesn't show something like
"text<NULL>........<NULL><EOF>"

i guesss you under stand..

just deleting...
i don't know ... please help me out..

Deleting it from memory is easy, you just copy the data after the part you delete over the part you want deleted.

Deleting it from memory is easy, you just copy the data after the part you delete over the part you want deleted.

but how do delete in case when i am using stdio.h file handling where the file gets saved when you "fflush(FILE *);"; or "fclose(FILE *);"

We're having a communication problem.

We are recommending that you create in memory a copy of what you want the file to contain. You are being specifically advised against trying to 'edit' the file as the user types keys.

The memory 'buffer' is what the user will edit. They can append to it, delete, whatever. (if you're having problems with editing in the buffer, ask about that.)

Once you have the buffer that is what should be in the file, you open the file, write the buffer and close the file.

If you're looking to make sure the file on disk is close to the buffer in memory, you could look into a periodic 'auto-save' of the file. (You could auto-save to the actual output file, but you should probably let the user know. Normally user files are only written on user command. Alternatively you could auto-save to a slightly different name -- like outputfile.asv or some other transformation of the real output name.)

This article has been dead for over six months. Start a new discussion instead.