I want my program to create a file. So it would be like the file is inside the program, and the program extracts it. What I did was write another program that would create an array of unsigned chars with all the hex values of the file I want to create, like this:
Code:
#define BLA_DATA_SIZE 22
#define BLA_DATA_NAME bla
const unsigned char bla[22] = {
0x62, 0x6C, 0x61, 0x20, 0x62, 0x6C, 0x61, 0x20, 0x62, 0x6C, 0x61, 0x20, 0x62, 0x6C, 0x61, 0x20,
0x62, 0x6C, 0x61, 0x2E, 0x2E, 0x2E
};
and then, my program would write that something like this
Code:
#include <stdio.h>
#include "bla.h"
int main(void)
{
FILE *outfile = NULL;
outfile = fopen("./bla.txt", "wb");
fwrite(BLA_DATA_NAME, sizeof(unsigned char), BLA_DATA_SIZE, outfile);
fclose(outfile);
return 0;
}
If the file I want to create is too big (about 20 or 30MB) then the compiler gives me an error that it failed trying to allocated 65536 bytes of memory. If I changed the unsigned char[] to an unsigned char*, then the compiler would give me a whole bunch of errors, saying that I have exceeded the maximum number of elements or something.
How can I make the program create bigger files (something like 100MB)? Is there a better way to do this?
Thanks!