This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

fopen "w+" or "r+" mode

Hello,

I need to modify or write a specified line in a text file.

I read in some forum that it is possible to do that using two files, by means the following steps:

1. Open the first file in read mode.

2. Read the file up to the line which has to be modified and copy this part of file to the second file.

3. Write the new line to the second file.

4. Read the rest of the first file and copy it to the second file.

5. Close the second file and remove the first file.

At the end of this procedure the second file looks like the first file with the modified line.

 

Instead of the procedure described above, I'd like to know if it is possible to modify a file using the "update mode" opening it in "w+" or "r+" mode.

In the MDK middleware of Keil It seems to be possible modify a file using the "update mode" if it is also used the FAT file system.

It is right or I'm wrong?

I tried to modify a file opening it in "w+" mode, but it doesn't work. The "w+" mode works like "w" mode: the content is destroyed.

Thanks in advance.

Giovanni.