Hi, -
I tried this question in another C forum and didn't get a response. Any help would be great.
=====================================================
The program that I have started to write opens a file and reads in structure formatted binary input:
if ((infile = fopen("flights.dat", "a+b") == NULL)
exit(EXIT_FAILURE);
rewind(infile);
while (ct < MAXSEATS && fread(&plane[ct], bufsize, 1, infile) == 1)
ct++;
No problem here, it reads them in fine. I have a function that adds new ones and one that deletes them. I would like to be able to write/rewrite them to random places and delete them if needed and replace it with a new one. It seems if I delete it, it never is removed from the file even if I use fwrite like:
scanf("%d", &del_seat);
plane[del_seat - 1].status = 0;
fwrite(&plane[del_seat - 1], bufsize, 1, infile);
Is this only possible with linked lists? If it can be done with fwrite, where do I point it's first argument to? And, should I open it in "w+b" instead of "a+b" mode?
Any help or resources would be greatly appreciated.
Thanks.
-Tyler
I tried this question in another C forum and didn't get a response. Any help would be great.
=====================================================
The program that I have started to write opens a file and reads in structure formatted binary input:
if ((infile = fopen("flights.dat", "a+b") == NULL)
exit(EXIT_FAILURE);
rewind(infile);
while (ct < MAXSEATS && fread(&plane[ct], bufsize, 1, infile) == 1)
ct++;
No problem here, it reads them in fine. I have a function that adds new ones and one that deletes them. I would like to be able to write/rewrite them to random places and delete them if needed and replace it with a new one. It seems if I delete it, it never is removed from the file even if I use fwrite like:
scanf("%d", &del_seat);
plane[del_seat - 1].status = 0;
fwrite(&plane[del_seat - 1], bufsize, 1, infile);
Is this only possible with linked lists? If it can be done with fwrite, where do I point it's first argument to? And, should I open it in "w+b" instead of "a+b" mode?
Any help or resources would be greatly appreciated.
Thanks.
-Tyler