Hot answers tagged

7 votes
Accepted

pset4 resize - fseek help (I think)

Your approach is correct, but you have three errors to deal with, one of which is irrelevant. First, as you guessed, your calculation for fseek is in error. In simple terms, you've placed parentheses ...
  • 64.6k
4 votes
Accepted

pset4 runtime error: unsigned integer overflow

You are subtracting from bi.biWidth on line 125. Since bi.biWidth is an unsigned long, it cannot contain negative values (-1 and so on), instead it's capacity to store positive values is doubled. So ...
  • 1,223
3 votes
Accepted

what's the purpose of fseek in PSET4?

First the padding. Keep in mind that the input file and the output file may or may not require the same amount of padding. In item 5, you don't examine the padding in the input file, you skip over it ...
  • 64.6k
3 votes
Accepted

pset 5 resize vertically - use of fseek

Assuming BWold is the width of the original image, this value represents the number of pixels in every row of the image, you need to consider that a pixel (or RGBTRIPLE) is three bytes. So in the ...
  • 1,369
2 votes
Accepted

fseek in pset4(whodunit)

Given that padding cannot be read by fread Who says the padding can't be read by fread? Of course it can and that's the main reason you need to skip it — in order to make fread read the first pixel ...
  • 17.4k
2 votes
Accepted

what is fseek() exactly doing?

1) My understanding is that lines are executed in order. Why would I position 'skip padding' only after the reading and writing commands as it happens in copy.c? you could also position it after add ...
2 votes
Accepted

PSet4 / Resize / Less: When to put the pointer back to the beginning?

In the first case, you want to wind back for all but the last iteration. In the second case, you would need a different condition, as you want to revert to the beginning of the line in all but the ...
  • 20.7k
2 votes
Accepted

How to use fseek along side arrays? Pset4 recover

for(int i = 0; i < MEMORYBLOCK; i++) { //read & store 512bytes in memory[i] fread(&(store[i]), 1, 1, inptr); //do we need *inptr instead? } If you want to ...
  • 18.4k
2 votes
Accepted

pset4/resize. problem with resize code and i don't know what to do

Well, you seem to be almost there, so I won't review all of your code, just give you some pointers: The first and most crucial tip is that you need to pass fseek() the number of BYTES as the second ...
1 vote
Accepted

pset6 server2 load() fseek() return -1 [SOLVED]

First, I love cacahuetes. Second: I can tell you one problem right away. This part won't work with pipe streams like php files: if (fseek(file, 0 , SEEK_END) != 0) { DBG_Print("\n%i\n", ...
1 vote

Pset4 odd behavior

First... you're using bi.biHeight directly here, but you're forgetting that it is a negative value. I won't say much more... think about that. bi.biSizeImage = ((bi.biWidth + padding) * bi.biHeight)...
1 vote

Yet again, problem with padding

One of the problems is that you're not resizing vertically. What you're doing is: 1) read one triple and write it as many times as needed by resize factor. Repeat this until a whole scanline has been ...
  • 1,677
1 vote
Accepted

Understanding padding and fseek()

While we think of an image as pixels and lines, i.e., a two dimensional array like a checkerboard, the data is stored in the file as a single linear string of data. Adding the padding all at once ...
  • 64.6k
1 vote
Accepted

Pset4 resize less comfortable, problems with fseek

Your guess is pretty good. Look at the following line: // reset stream pointer for next scanline fseek(inptr, -((biOut.biWidth * sizeof(RGBTRIPLE)) + outPadding), SEEK_CUR); First, this ...
  • 64.6k
1 vote
Accepted

CS50 Pset4 Resize - Vertical Sizing

Have you looked at the raw image data using xxd? The image data for anything larger than n=1 is far too much! The code is using the output file's biHeight and biWidth to control reading the input ...
  • 64.6k
1 vote
Accepted

Pset 4 Resize fseek()?

Too many one letter variables for me to really understand your code. But reset probably should not include intpadding. And the j++ within the innermost loop also is quite odd.
  • 20.7k
1 vote
Accepted

fseek doesent do what i expected

by fseek(inptr, (sizeof(RGBTRIPLE) * or_Width) + or_padding, SEEK_SET); you move cursor back to the very beginning of the file (SEEK_SET), and then move it to the beginning of the next row (sizeof(...
  • 1,139
1 vote
Accepted

Vertical resizing with fseeks()

Not only with fseek. In the beginning you redefine bi.biWidth and bi.biHeight - now its new width and new height. But when you iterate over scanlines and pixels, you want to do it over infile's ones, ...
  • 1,139
1 vote
Accepted

pset 4: resize adding in black pixels

fseek(inptr, bf.bfOffBits + ((oldWidth * 3) * i) + newPadding, SEEK_SET); You want to go to the start of i line of infile. Each infile line is (oldWidth * 3 + oldPadding) bytes. Multiply it by i and ...
  • 1,139
1 vote

CS50 pset4 recover: buffer type and fseek questions

an int is 4 bytes an unsigned char is 1 byte so buffer[3] in char is the 4th byte but in int it is the 13-16 bytes. so when using int you are not actually checking the first 4 bytes, but the first 16.
1 vote

Pset 4 Resize makes a very colorful picture (not green!)--padding problem?

You change bi.biWidth and bi.biHeight to new scale using bi.biWidth = bi.biWidth * enlarge; bi.biHeight = bi.biHeight * enlarge; and then use code that relies on the values to represent the ...
  • 20.7k
1 vote
Accepted

pset6 load - why does fseek(file, 0, SEEK_END); size = ftell(file); not work?

I'll quote some useful answers, because this question has been asked before: First Kareem Zidade on a post on facebook: You'll learn more about that in the following few weeks of the course, but ...
1 vote
Accepted

pset4 resize fseek() - non proper work

You could use fseek(inptr, -bi.biWidth * sizeof(RGBTRIPLE), SEEK_CUR); (no padding, as you never read some) to go back to the start of the line where you fseek at the moment, and after that loop, ...
  • 20.7k
1 vote
Accepted

pset4 Resize - Trouble Understanding Padding

According to MSDN biSizeImage The size, in bytes, of the image. This may be set to zero for BI_RGB bitmaps. If biCompression is BI_JPEG or BI_PNG, biSizeImage indicates the size of the JPEG or PNG ...
  • 7,356
1 vote
Accepted

pset4 vert resize doesn't work with 1x1 px image

biNEW.biHeight = n * abs(bi.biHeight); The sign of the biHeight parameter tells the computer whether to paint the image from top to bottom, or from bottom to top. By applying the abs() function, it ...
  • 64.6k
1 vote

Help with fseek and fgets

Fseek works by moving the file pointer, indicated by the FILE pointer in our case, forward or backward. So whenever you use functions that work with file streams, you should keep in mind where the ...
1 vote
Accepted

resize pset 4 confused on number of things

There are a number of issues that need to be fixed. Since the philosophy of this forum is to guide people to solutions and not just to fix code, I'll point you at two subtle but major issues that will ...
  • 64.6k

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