The final part is to close both files. This ensures that the last part of the file gets written to disk. During file writes, many of the writes don't go directly to disk but are held in fixed sized buffers. Once a write fills the buffer then the entire contents of the buffer are written to disk.
There is a file flush function that forces flushing and you can also specify file flushing strategies but those are intended for text files and will be covered in the next tutorial.
ShowRecord Function
Having written the two files, it's useful to test that we can retrieve any specified record from the data file. For this we need to know two things:- Where it starts in the data file.
- How big it is
fseek( ftindex, sizeof(index)*(recnum) ,SEEK_SET ) ;SEEK_SET is a constant that specifies where the fseek is done from. There are two other constants defined for this.
fread( &index,1,sizeof(index),ftindex) ;
- SEEK_CUR - seek relative to current position
- SEEK_END - seek absolute from the end of the file
- SEEK_SET - seek absolute from the start of the file
fseek( ftindex, sizeof(index) ,SEEK_SET ) ;
On the next page : More about example 2

