prev up next   top/contents search

comp.lang.c FAQ list · Question 12.30

Q: I'm trying to update a file in place, by using fopen mode "r+", reading a certain string, and writing back a modified string, but it's not working.

A: Be sure to call fseek before you write, both to seek back to the beginning of the string you're trying to overwrite, and because an fseek or fflush is always required between reading and writing in the read/write "+" modes. Also, remember that you can only overwrite characters with the same number of replacement characters; there is no way to insert or delete characters in place. Finally, remember that overwriting in text mode may truncate the file at that point, and that you may have to preserve line lengths. See also question 19.14.

References: ISO Sec.

prev up next   contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North