C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-27-2008, 09:47 AM   #1
Registered User
 
Join Date: Oct 2008
Posts: 58
Random acces write to a binary file

Hi,
I'd like to have your expertise on writing in random mode - after setting the current pointer with fseek - into an existing binary file. I'm getting somehow confused with a bunch of options for fopen_s, including an "R" (for random), and a "c" to force "hard flushing" into the disk (bypassing the system's buffers), that I read about for the first time. What would be the right function to write - so that to avoid writing byte by byte?
Thanks!
Opariti is offline   Reply With Quote
Old 10-27-2008, 12:20 PM   #2
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,657
Just a regular fopen() with a mode of "r+b" should suffice.

Then seek to where you want to write, then fwrite() as much data as you please.

Call fflush() if you switch back to reading the file.

> I'm getting somehow confused with a bunch of options for fopen_s, including an "R" (for random), and a "c" to force "hard flushing" into the disk
All of which is non-portable.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

Salem is offline   Reply With Quote
Old 10-28-2008, 06:05 AM   #3
Registered User
 
Join Date: Oct 2008
Posts: 58
I've tested the optimal configuration: fopen() with "wbc" mode and fwrite() as per the manual. Good performance since fseek() does automatically fflush() prior to any field pointer positionning into the file. Thanks!
Opariti is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Read and write binary file? Loic C++ Programming 2 10-29-2008 05:31 PM
help with text input Alphawaves C Programming 8 04-08-2007 04:54 PM
airport Log program using 3D linked List : problem reading from file gemini_shooter C Programming 3 03-04-2005 02:46 PM
How to store n write binary file? megablue C Programming 4 10-23-2003 03:53 AM
simulate Grep command in Unix using C laxmi C Programming 6 05-10-2002 04:10 PM


All times are GMT -6. The time now is 12:41 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22