Editing a text file 
Author Message
 Editing a text file

fputs(str, fp);

But, you may need to watch the string lengths...

Alan

* Sent from RemarQ http://www.*-*-*.com/ The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



Sun, 29 Sep 2002 03:00:00 GMT  
 Editing a text file
Hi,

After using fgetpos to store the location of a line of text in a file, I
then used fsetpos to return to that line of text. I now want to
overwrite this line with a new line of text. How do I do it?

Thanking you in anticipation,

John.



Mon, 30 Sep 2002 03:00:00 GMT  
 Editing a text file
Groovy hepcat John Baker was jivin' on Thu, 13 Apr 2000 13:51:18 +1000
in comp.lang.c.
Editing a text file's a cool scene! Dig it!

Quote:
>After using fgetpos to store the location of a line of text in a file, I
>then used fsetpos to return to that line of text. I now want to
>overwrite this line with a new line of text. How do I do it?

  Well, you can't. At least, you can't portably. You'll have to copy
the file to a new file up to the line you want to replace, write the
new line, then copy the rest of the file. After that, remove the
original file and rename to new one to the original's name.
--

----- Dig the EVEN NEWER, MORE IMPROVED news sig!! -----

-------------- Shaggy was here! ---------------
    http://aardvark.apana.org.au/~phaywood/
============= Ain't I'm a dawg!! ==============



Thu, 03 Oct 2002 03:00:00 GMT  
 Editing a text file

Quote:

> Groovy hepcat John Baker was jivin' on Thu, 13 Apr 2000 13:51:18 +1000
> in comp.lang.c.
> Editing a text file's a cool scene! Dig it!

> >After using fgetpos to store the location of a line of text in a file, I
> >then used fsetpos to return to that line of text. I now want to
> >overwrite this line with a new line of text. How do I do it?

>   Well, you can't. At least, you can't portably. You'll have to copy
> the file to a new file up to the line you want to replace, write the
> new line, then copy the rest of the file. After that, remove the
> original file and rename to new one to the original's name.
> --

Certainly it is possible within the confines of standard C.
I always believed that fopen() with "r+" mode was intended for
precisely this purpose.

To the OP: make sure you open the file with fopen("myfile","r+")
and you can then overwrite any part with any of the standard stream
writing functions. It is probably a good idea to use fflush() before
executing another stream read function.

Malcolm Kay



Sat, 05 Oct 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Which is the Best Way To Edit a Text File

2. Editing a text file

3. Problem editing big text files

4. Editing text file in c

5. Text Editing Resources (.rc files)

6. Wanted: locating positions in edited text files

7. Show text file in edit box ?

8. Text to Rich Edit conversion on read from file

9. rich edit not able to load text from file

10. What is easiest way to read text file into mem and push into edit control

11. Putting text into an Edit box from a file

12. Wrapping text in text box or edit box

 

 
Powered by phpBB® Forum Software