Hey, so lets say I get a file as the first command line argument.
int main(int argc, char** argv) {
unsigned char* fileArray;
FILE* file1 = fopen(argv[1], "r");
}
Now how can I go about reading that file, char by char, into the char* fileArray?
Basically how can I convert a FILE* to a char* before I know how big I need to malloc the char*
I know a possible solution is to use a buffer, but my problem here is I’m dealing with files that could have over 900000 chars, and don’t see it fit making a buffer that is that large.
If only “real” files (not stream, devices, …) are used, you can use
stat/fstator something liketo get the file’s size beforehand. Then you can malloc and read.
But since file1 might change in the meantime you still have to ensure not to read beyond your malloced size.