So, I've figured out how to change the file headers and all. Works beautifully. The large image is the right size. I couldn't be happier. However, the large bmp image is just filled with neon green pixels. I would imagine that the part of my function that reads each pixel from the input file (pointer) and then writes it get stuck somewhere in a loop. I suppose it is not an infinite loop per se, since that would me I would spill over the allotted space for the bmp. I am really stuck here. My code follows below. Any and all hints would be greatly appreciated.
1 Answer
Your problem is with your fseek()
s.
You should fseek()
back to beginning of the current line each time you read all the pixels of this line. You should do this n
times for each line.
You should fseek()
at the beginning of the next line after the n-th time you print a line.
Also, when you want to fseek()
backwards, the offset
parameter should be negative. In your case, your comment says that you fseek()
backwards, but the offset
is positive.
I hope this will help without spoiling the good part of figuring it out on your own. :D
-
Thank you for your quick response. I've fixed what you suggested. It worked perfectly and the large.bmp output is indeed a multiple of the input file by factor n. I was so happy to see that. However, upon passing the function to check50 it presents me with these messages. I think that's strange considering the program does what it should. Is there a way to figure out what these messages mean, since there are kind of slashed into pieces? Jul 14, 2017 at 15:45
-
~/workspace/resize/ $ check50 2016.resize.less bmp.h resize.c :) resize.c and bmp.h exist :) resize.c compiles :( doesn't resize 1x1-pixel BMP when n is 1 \ expected an exit code of 0, not output of "Padding in: 3\nNew width: 3\nPadding: 3..." Jul 14, 2017 at 15:46
-
:( resizes 1x1-pixel BMP to 2x2 correctly when n is 2 \ expected an exit code of 0, not output of "Padding in: 3\nNew width: 6\nPadding: 2..." :( resizes 1x1-pixel BMP to 3x3 correctly when n is 3 \ expected an exit code of 0, not output of "Padding in: 3\nNew width: 9\nPadding: 1..." :( resizes 1x1-pixel BMP to 4x4 correctly when n is 4 \ expected an exit code of 0, not output of "Padding in: 3\nNew width: 12\nPadding: ..." Jul 14, 2017 at 15:46
-
:( resizes 1x1-pixel BMP to 5x5 correctly when n is 5 \ expected an exit code of 0, not output of "Padding in: 3\nNew width: 15\nPadding: ..." :( resizes 2x2-pixel BMP to 4x4 correctly when n is 2 \ expected an exit code of 0, not output of "Padding in: 2\nNew w Jul 14, 2017 at 15:46
-
1Nevermind, forgot to remove the fprints I put in place for debugging. Thank you so much for your help. I have removed the code form the original post for academic honesty! :) Jul 14, 2017 at 15:48