I am trying to make a file extraction program in C and I can't get it to work. It compiles ok, but it has a run-time error. I hope you can figure out what I am trying to do here. I don't know if there is a standard way to do this. I am going to make a table with length of files later. Is there a way to determine EOF without having a table of lengths?
Here is the layout of the file:
1. extraction program
2. 4 bytes for number of files in archive
3. table of files (each 16 bytes long)
4. length of each files in table (not implemented)
#include "stdio.h"
int main(int argc, char* argv[])
{
//Declair vars
FILE *self;
int fcount = 0;
int i;
//Size of this program (the stub)
const int F_SIZE = 6143;
//Open self, set pointer to the end of the stub
self = fopen(argv[0], "rb");
fseek(self, F_SIZE, SEEK_SET);
//Read integer for number of files in archive
fread(&fcount, 4, 1, self);
char filenames[fcount][16];
//Loop through the file names
for(i = F_SIZE + 4; i < F_SIZE + 4 + (fcount * 16); i+=16)
{
fseek(self, i, SEEK_SET);
fread(&filenames[i][16], 16, 1, self);
}
fclose(self);
for(i = 0; i < fcount; i++)
{
self = fopen(&filenames[i][16], "w");
//This part is just to test if it can make the files
fprintf(self, "%c", 144);
fclose(self);
}
return 0;
}