How to write the first line in a text file when opened file as 'a+'
Show older comments
I'am having issues rewriting the first line of a text file when I open the file as 'a+'. Example:
file = fopen('example.txt','a+'); frewind(file); fprintf(file,'%f %u %u',version, numlines, newChecksum); fclose(file);
The objective of the code is to add update the information from the first line of the file. The problem is that when I do the fprintf() it writes the info. at the end of the file not at the beginning where the file pointer is currently located after the frewind(). I have also tried the fseek. Both frewind and fseek work because if I use the command fgets() to get the first line it dose get the info. located at the beginning to the file.
Accepted Answer
More Answers (0)
Categories
Find more on Low-Level File I/O in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!