New answers tagged

0

Let's look very closely at this code: while(fread(&file, 512, 1, input) == 1) { //check if file is jpeg if (file[0] == 0xff && file[1] == 0xd8 && file[2] == 0xff && (file[3] & 0xf0) == 0xe0) { //if a previous file is open, close it if (counter != 0) fclose(img); } //initialize new ...


0

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[0] == 0xff && ...


1

This (JpegBlocks[0] = 255) uses the set operator, not the comparison operator. This allocation char StrFileHolder[7]; won't accomodate the null terminator when sprintf creates the string.


0

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 ...


1

A jpeg signature is 4 bytes; program only tests 3. Program only writes one 512-byte block.


1

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[8]; You almost had it. In essence, I'm not sure what I could use to close the ...


1

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 ...


Top 50 recent answers are included