By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,943 Members | 1,921 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,943 IT Pros & Developers. It's quick & easy.

Explanation of modifying data

P: 6
Can anyone explain me what is the meaning of placing file pointer at the beginning of record to be modified while trying to modify data in files in c++
Jul 31 '17 #1
Share this Question
Share on Google+
3 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
That pointer contains the address of where the file data is located.

If you don't know where the file is located, then how can you access the data?
Jul 31 '17 #2

Expert 100+
P: 2,398
How it works in C (presumably C++ is similar) ...

There are many files in your computer. Which file you are working with is controlled via a pointer to type FILE. This pointer gets its value from fopen() or freopen().

A file is made up of many bytes. Which byte you are currently working with is controlled by the stream position indicator - a secret pointer hidden in the FILE structure that you never access directly. It is initialized when you open the file; and advances as you read from or write to the file. You can also use fseek() to modify the stream position indicator.

Which kind of file pointer are you asking about?
Aug 1 '17 #3

Expert 100+
P: 2,398
Sounds like you want to modify a file.

Easiest way to do this is to read the entire input file into a memory buffer, modify the memory buffer as needed, and then write the buffer out to a new file (which might happen to have the same name as the input file).

You have to get clever if the input file doesn't fit in memory.
Aug 1 '17 #4

Post your reply

Sign in to post your reply or Sign up for a free account.