Wrox Programmer Forums
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old October 28th, 2003, 03:04 AM
Authorized User
 
Join Date: Oct 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help

Hullo wrox,
 I'm stack on this project,
I need to add a record to the Dbase in C++, incase the user wants to add a new client.
I read the data entered but i have to first seek to the current file position using the memset/fseek function, how do i find the position and add data to that location?

Thanks,
Programmed.

Reply With Quote
  #2 (permalink)  
Old October 30th, 2003, 07:18 PM
Registered User
 
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

A file is like an array. You can't simply 'insert' bytes in the middle. The easiest approach is as follows:

1) create a temporary file.
2) write the first set of bytes of the database to the temp file.
3) write the new set of bytes to the temp file.
4) write the final set of bytes of the database to the temp file.
5) if no errors have occured, delete the original and rename the temp file.

- Sebastian Garth

"The process of preparing programs for a digital computer is especially attractive, not only because it can be economically and scientifically rewarding, but also because it can be an aesthetic experience much like composing poetry or music." - Donald Knuth
Reply With Quote









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.