How to clear the character in the file???

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2007
Posts: 68
Reputation: Rhohitman is an unknown quantity at this point 
Solved Threads: 4
Rhohitman's Avatar
Rhohitman Rhohitman is offline Offline
Junior Poster in Training

How to clear the character in the file???

 
0
  #1
Jan 23rd, 2009
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.

  1. //i tried it like this
  2. fseek(fp,-1,SEEK_CUR);
  3. fputc(<character to be replaced>,fp);
  4. fseek(fp,-1,SEEK_CUR);
Chazing Dreams ;'P
Shhhh.......ZZzzzzzzzzzzzzzzzzzzzz.....
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: How to clear the character in the file???

 
0
  #2
Jan 24th, 2009
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.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 68
Reputation: Rhohitman is an unknown quantity at this point 
Solved Threads: 4
Rhohitman's Avatar
Rhohitman Rhohitman is offline Offline
Junior Poster in Training

Re: How to clear the character in the file???

 
0
  #3
Jan 24th, 2009
Originally Posted by WaltP View Post
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!
Chazing Dreams ;'P
Shhhh.......ZZzzzzzzzzzzzzzzzzzzzz.....
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: How to clear the character in the file???

 
0
  #4
Jan 24th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 68
Reputation: Rhohitman is an unknown quantity at this point 
Solved Threads: 4
Rhohitman's Avatar
Rhohitman Rhohitman is offline Offline
Junior Poster in Training

Re: How to clear the character in the file???

 
0
  #5
Jan 24th, 2009
Originally Posted by Salem View Post
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..
Last edited by Rhohitman; Jan 24th, 2009 at 11:52 am.
Chazing Dreams ;'P
Shhhh.......ZZzzzzzzzzzzzzzzzzzzzz.....
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: How to clear the character in the file???

 
0
  #6
Jan 24th, 2009
Deleting it from memory is easy, you just copy the data after the part you delete over the part you want deleted.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 68
Reputation: Rhohitman is an unknown quantity at this point 
Solved Threads: 4
Rhohitman's Avatar
Rhohitman Rhohitman is offline Offline
Junior Poster in Training

Re: How to clear the character in the file???

 
0
  #7
Jan 24th, 2009
Originally Posted by Salem View Post
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 *);"
Chazing Dreams ;'P
Shhhh.......ZZzzzzzzzzzzzzzzzzzzzz.....
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 570
Reputation: Murtan is a jewel in the rough Murtan is a jewel in the rough Murtan is a jewel in the rough Murtan is a jewel in the rough 
Solved Threads: 93
Murtan Murtan is offline Offline
Posting Pro

Re: How to clear the character in the file???

 
0
  #8
Jan 24th, 2009
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.)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC