Updating a file random access in c

After writing it, the next file will start from 54th byte on the disk.Obviously, this is very wasteful operation of computer time.The file needs to be opened for updating (i.e., to allow both reading and writing).That’s what the part is unnecessary but still recommended for clarity on Unix and Unix-like systems—however, it’s absolutely crucial on other platforms, such as Macintosh and Windows).As you already know that the length of the array can be longer than the length of the string inside it.

updating a file random access in c-42updating a file random access in c-22

That will give us the number of characters inside the string instead of the array length.Similarly in case of files, the space occupied by a file (file size) can be more than the actual data length of the file itself.Why the size of the file can be greater than the actual data contained in that file?Once you have a file object that is correctly opened (i.e., for update, and as a binary rather than a text file), you can perform as many updates on the file as you want before closing the file again.These calls are shown here to emphasize the proper technique for opening a file for random-access updates and the importance of closing a file when you are done with it.

Leave a Reply