Let's look very closely at this code:
while(fread(&file, 512, 1, input) == 1)
//check if file is jpeg
if (file == 0xff && file == 0xd8 && file == 0xff && (file & 0xf0) == 0xe0)
//if a previous file is open, close it
if (counter != 0)
//initialize new ...
while (fread(&buffer, BUFFER_SIZE, 1, inputf) == 1) // repeat until end of card
fread(&buffer, BUFFER_SIZE, 1, outputf); // (data, size, number, inptr) // read 512 bytes into a buffer
Why are you trying to read from outputf into buffer??!! Clearly outputf is NULL pointer which results in segfault
if (buffer == 0xff && ...
This code looks for the start of a jpg, and closes the previous open file (if it exists) then starts a new file by adding the 512 Bytes of the current block. From the background section: "Realize, of course, that JPEGs can span contiguous blocks. Otherwise, no JPEG could be larger than 512 B." The case where there's not a new header, but already an ...
char *flname = "0.jpg";
The string here is immutable. Writing to it again is undefined behavior. You need to stack allocate space for a file name. 000.jpg is 7 characters and you need one extra byte to store the null terminator so 8 characters will do it. char flname; You almost had it.
In essence, I'm not sure what I could use to close the ...
RE:fread - it doesn't matter either way. The fread call is going to multiply the sieof() value x the number of them ( or parameter 2 x parameter 3 ) and read that many bytes. You just need to make sure that the sizeof(buffer) is 512 in this case. Either way, it will be 512 bytes read.
The program doesn't know how big the file is. Go back to the spec. The ...