Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
You will have to read the entire file, count the required number of lines, then replace the piece between two newlines with the edited value, and finally rewrite the entire file. You can optimize a little and rewrite not the entire file, but only starting from the changed line. Use fseek to move to the beginning of the line/file, fwrite to write new data, and ftruncate to truncate the file if it gets shorter.
I originally had a structure and it has an id. The console asked for the number of the line that I would like to replace, then I looked for this id in the structure and changed all its values to new ones, and then overwrote the file. Through fseek with fwrite I tried, but something didn’t work out for me, most likely I did something wrong.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question