Hot answers tagged

4

After edit: For reference, here is the pseudocode from the walkthrough: for each row       for each pixel          write to array n times       for n times          write array to outfile  &...


3

Why is it that the simplest errors are the most frustrating and then others hide it? You have two major issues to deal with, followed by a handful of minor ones. I'll point you at the majors and you can debug the rest. First, the infinite loop is being caused by your unload function. If i is never changed, the loop will never end. A rethink of the code is ...


2

The reason is that the third parameter is NOT the number of times to write out the contents of buffer. It's the number of ELEMENTS, the second parameter (the size of an element) to be written. For illustration, let's say that we're working with letters. Say that source is a char array and contains abcdef. Now, say that you had this: fwrite(source, 2, 3,...


1

There is "\n" (new line) char in the end of the first raw. So there are 33 chars, while you read-write only 32.


1

When the program has opened the card.raw file and is reading into the buffer, once the program has completed one loop iteration, how does it know to read the next block of bytes and not just the same ones again? R.: fread() will ALWAYS read the next block. It'll only read the same block again if you force the file position indicator back with fseek(...


1

The code does two fread() calls at the top of the while loop. The data from the first fread isn't being processed, it's just being overwritten when the loop comes back around. This means that half the data is being discarded, including, conicidentally, half of the signature blocks. The inptr file pointer doesn't reset because you're using a different buffer,...


1

The most obvious difference is the return value: fread returns the number of elements read (in this case, the number of sizeof(int)'s). If all goes well, the first formulation will return 10, while the sum of the individual fread return values (each having a return value of 1) in the second formulation should likewise equal 10. Also, if the stream (infile) ...


1

Delete the semicolon at the end of the line. It marks the end of the while loop, just like a closing curly brace.


1

First, when your program reaches line 74, you already have a file open that has it's location stored in a pointer you named img. When your program goes to write to this, it does not try to reopen it or recalculate where that pointer should be going to using the path that you have laid out. Instead, it reads the location that is stored within img even though ...


1

Look at the following code: FILE *img = fopen(filename, "r"); ... while(findJpg(ptr, buffer, blocks) == -1) { fwrite(&buffer[i], 512, 1, img); Question: How is the code going to write to the output file when it is opened for READ??? ;-) Next question, why not just use buffer in the write statement? There are more and significant ...


1

I was researching on this as well and found this page with a comprehensive answer here. sizeof(BYTE) is equivalent to 1 so the second and third "variations" are the same. Both first and second variations work in this case because the number of bytes in card.raw is exactly in multiples/blocks of 512. If fread(arr, 512, sizeof(BYTE), file) was used AND the ...


1

Having a look at your code was really helpful, I was having a hard time with this problem because I cant fully understand how fread works. You keep reading rawPtr and sending it to buffer, and the size of it to bytesRead, but I dont understand why it wont read the same block of 512B, you are not telling the program to go to the next block of 512, I suppose ...


1

I'm not getting a really clear picture of the problems you're having (no pun intended), but I'll tackle it anyways. First, you don't need to know how big the files are, just that their data will be in sequence in the input file. Once the code finds a block of data with a signature, that signals the beginning of a new output file. If one's already open, ...


1

fwrite(&triple, sizeof(RGBTRIPLE), n, outptr); This means to write n consecutive blocks of data of size sizeof(RGBTRIPLE)starting at &triple, not to write one block n times. If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)


1

The for loop will write n copies of the data stored at a to the file. The single fwrite will write n*sizeof(whatever) bytes starting at the address of a. If does NOT write n copies of a. The former is the way to write multiple copies of one item, the latter is the way to write n consecutive items from memory. If this answers your question, please click ...


1

The logic of the program has some serious flaws. While individual statements are functioning correctly, its the overall logic that isn't working. Go back and look at what the program is doing. Read until first signature is found. Open the first file and write out the first block. In the inner while loop, read the next block. Write the block out to the ...


Only top voted, non community-wiki answers of a minimum length are eligible