How to write the first line in a text file when opened file as 'a+'
显示 更早的评论
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.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Low-Level File I/O 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!