Right now, when I use write system call over and over again, it just appends to a file lets call file.txt if I were to call sys call write in C, on file.txt, it would just constantly. There is a circumstance where given that same file, I want to erase everything from it, and add just one line. How would I go by doing this? I don’t want to create a new file, I want to working in that same file.
Thanks!
Just call
truncateorftruncateto cut the file to zero bytes. Then write the line you want. You don’t need to close or re-open the file, you can use your existing handle.