I'm thinking you got a little confused when you were writing this part. Note that I added comments, "LINE A" and "LINE B":
// char for the write
char writeFile[count * sizeof(buffer)]; // LINE A
if (buffer == 0xff && buffer == 0xd8 && buffer == 0xff && (buffer & 0xf0) == 0xe0)
//opening the file for writing
FILE *output = fopen(writeFile, "w"); // LINE B
Let's look at what happens in this code. Line B attempts to open the output file, but it's more or less failing. the fopen() call uses the string in writefile as the filename to open. But what's in writefile? Let's go back to LINE A.
In LINE A, the char array variable
writefile is declared, and it's declared to have a size of count * 512. Why? You already have buffer to hold each 512 bytes read in from the input file. That's an awful lot of space to use for a text string with, at most, 7 chars plus the end of string marker!
Also, and more relevant, the filename of the output file is never put into the writefile string (char array)! So, when it creates a filename, it uses whatever junk is in the array. I'll wager that you have some strangely named files in your IDE. You should do some cleanup and delete them while fresh on your mind.
The bottom line is that this code is going to have some very unpredictable behavior in creating files.
It looks like you've conflated the use of writefile to hold the filename with holding the buffer contents. The code isn't creating files with the correct file names, so it's failing when check50 runs it. BTW, did you test it yourself before running check50??? Didn't you notice that there were no output files with correct names????
Here's another hint. Declare the output file pointer before the start of the while loop, but set it to NULL at that point. Call fopen() later, inside the for loop as needed.
There's more code to be written, so this will get you going. Happy coding!
If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance.;-)