FILE* inFile = fopen(inF, "rb");
if (inFile == NULL) {
printf("Invalid input!\n");
exit(EXIT_FAILURE);
}
char* bigBuffer;
char* nextChar = (char*) malloc(sizeof(char));
unsigned long i = 0;
unsigned long j;
while ((j = fread(nextChar, sizeof(char), 1, inFile)) == 1) {
i += j;
}
bigBuffer = malloc(i * sizeof(char));
fread(bigBuffer, sizeof(char), i, inFile);
fclose(inFile);
printf("%s\n", outF);
FILE* outFile = fopen(outF, "wb");
//if (outFile == NULL)
//printf("null\n");
j = fwrite(bigBuffer, sizeof(char), i, outFile);
printf("%lu\n", j);
fclose(outFile);
free (bigBuffer);
free (nextChar);
I'm trying to write a binary file using fopen in wb mode. After running my program, a file of the proper name is made in the proper place, but I just can't open it or read it. When I try to open it, a message pops up saying "Can't open...." In addition, the name of the file itself isn't formatted properly in Finder (I'm on a Mac). The name is elevated and cut off a little. It definitely looks like something is wrong with the file. I tried just making a regular file using fopen in w mode, and that worked beautifully. So I'm pretty sure I'm just doing something wrong when it comes to writing binary files using wb mode. Can anyone help? Thanks.