Fseek() overwrite problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Fseek() overwrite problem

Hello. I am trying to use fseek() to write something on the first line of my text file. The problem is that fseek() overwrites the already existing content of the first line to write the new one that i add by fputs(). What should i do? Thanks in advance!

29th Oct 2017, 1:28 PM
spykate
spykate - avatar
2 Answers
+ 3
fseek()? C#? Why does it look more C to me? Be frank, is this for C# or C? These are different languages. If the question is for C: So you wish to have your new line 'before' the original data? Thus, if you were to add "Hello" to a file containing "World", should the new data in the file be - "HelloWorld" ? For this, you need to get a new file, write the new data, then the old data, then remove the old file, and then rename the new one to the original name. We have functions remove() and rename() in stdio.h for the same.
29th Oct 2017, 3:38 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 1
Thank you very much and i am sorry for asking in the wrong language-chatroom
29th Oct 2017, 3:55 PM
spykate
spykate - avatar