Question 12.30

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.


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; see also question 19.14.

References: ANSI Sec. 4.9.5.3
ISO Sec. 7.9.5.3


Read sequentially: prev next up top


This page by Steve Summit // Copyright 1995 // mail feedback