0

I have it upto here and now it does resize, but the image is off. Having a hard time trying to figure out where its going wrong since debugger etc doesnt reveal much info on files and arrays.

https://pastebin.com/mS2jmZGj

1

Think of each pixel as something more concrete (you should check the documentation format in the header file and write things down in a paper if you're having a hard time understanding this). If it was a letter how would you make a program that reads a letter "a" and spits "a" n times? This fseek, I think you can imagine something like using a text editor without a mouse, in the sense of moving the cursor using the keyboard.

fseek(fileprt, offset, from) 

This is the way you tell C to move the cursor inside a file, which fileptr pointer is pointing at, without reading anything. The offset is how many units do you want to move it, you should use the sizeof function to jump into "words" (which are pixels in this case, words don't have the same size, but I think you get the idea). The "from" parameter its the starting point, if you call the function fseek(fileptr, sizeof(word), SEEK_SET) this moves the cursor after the first word from the start of a file (SEEK_SET). Then if you call fseek(fileptr, 4*sizeof(word), SEEK_CUR) afterwards, it would move 4 words after the current (SEEK_CUR parameter) cursor position, so your cursor would be right after the fifth word. I don't know if this is clear, or if this what you were asking.

4
  • hey thanks for the tips. I got further but something is still off with my image and code. Do you mind taking a look at the paste bin link I posted and offering some insight on how to debug or what I am missing? Apr 2 '19 at 12:45
  • Check how you're using padding in the first fseek, why would you use it there? It doesn't seem you passed through it, but you're going back, this padding thing is kinda confusing. I had to run some tests printing things to check what was related to what when I had to write the headers of the output file. Check how the copy file runs and imagine how a file is looking as it runs.
    – user23369
    Apr 2 '19 at 17:24
  • 1
    Yup I was able to figure it out. But thanks for the help! :) On a separate note so I can develop my debugging and building skills, what were you printing and how? That has been the most difficult thing with dealing with this problem set, as it is hard to know exact what is in the array and files. Apr 3 '19 at 18:16
  • I'm not an experienced C programmer, but you can print everything (even pointers can be printed). I think the debugger does a better job tracking what is happening inside a program, but printing is a good alternative to debug as you're coding. Things that I usually print are indexes and whatever is changing in loops, values of variables to check if something is running properly, values of something that I don't understand. I understood what the values in that header file meant using print statements, the documentation does a good job explaining it, but print is always print.
    – user23369
    Apr 3 '19 at 19:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .