More file stuff

After using fseek() to locate parts of files, how can I get rid of them? (Directly from file)  Is there another function I can use?
Thank You!
pingleAsked:
Who is Participating?
 
jkrConnect With a Mentor Commented:
Well, if you had e.g. 6 records of the same size in a file and want to skip the 4th, you'd

#include <stdio.h>

struct RECORD {

 int i1;
 int i2;
 int i3;
 int i4;
};
void main () {

RECORD record;

 FILE* pIn = fopen ( "records.fil", "rb");
 FILE* pOut = fopen ( "new_records.fil", "wb");

 for ( int i = 0; i < 6; i++) {

   fread ( &record, sizeof ( RECORD), 1, pIn);

   if ( 3 == i) continue; // skip the 4th record at index 3

   fwrite ( &record, sizeof ( RECORD), 1, pOut);

 }

 fclose ( pIn);
 fclose ( pOut);
}

(error checking omitted for brevity)
0
 
jkrCommented:
You mean, you wat to delete a section from a file? That's not possible. All you could do is "copying" the file while going through it and skipping the part you don't want...
0
 
pingleAuthor Commented:
Could you tell me how to do that?  That should serve my purpose just fine.
0
 
pingleAuthor Commented:
Thank you AGAIN! I really appreciate it!
~Pingle
0
All Courses

From novice to tech pro — start learning today.