![]() |
| | #1 |
| Registered User Join Date: Oct 2008
Posts: 58
| Random acces write to a binary file 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 | |
| | #2 |
| and the hat of Jobseeking 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. |
| Salem is offline | |
| | #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 | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |