I have check with the CS50 peek and all are green lit. The BMP on the other hands just shows the original (colours x n) and the rest of the picture is just green.

I have read something about File indicator pointer. I tried to add another fseek function so that it rereads the line n times. But I failed many times.

Here is the part of the code that I have a problem:

// iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
    // repeat the same line n times
    for (int Nrow = 0; Nrow < resize_num; Nrow++)
        // iterate over pixels in scanline
        for (int j = 0; j < bi.biWidth; j++)
            // temp storage
            RGBTRIPLE triple;

            // read RGB triple from infile
            fread(&triple, sizeof(RGBTRIPLE), 1, inptr);

            // write RGB triple to outfile
            for (int i_th = 0; i_th < resize_num; i_th++)
                fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
        // skip over padding, if any
        fseek(inptr, padding, SEEK_CUR);

        // add padding to the outfile 
        for (int k = 0; k < NEWpadding; k++)
            fputc(0x00, outptr);

I have been at this for more than a month now. Thanks in advance.


You are almost there, but one piece is still missing. I'll assume that when your resize factor is 1, it works fine. (If not, you need to fix that first.)

When you are processing a resize (n) greater than 1, the code needs to read a line from the input file, expand it by copying each pixel n times, skip the input file's padding, and write the output file's padding. You are doing all of this.

The one remaining step is this: the code needs to go back to the beginning of the current line being processed in the input file using fseek() until it has been processed n times. After the nth time, the file pointer needs to be at the beginning of the next line in the input file.

The reason you are getting all green at the end of the output file is that the code is only doing the horizontal expansion, but has the same number of lines as the original file, and then the rest of the file is being filled out with whatever is left in triple.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

  • I have just read your answer. I was away for some days. The problem that I have with fseek is that I think I am resetting the pointer but it doesn't. Here is the fseek that I added in the second loop: fseek(inptr, -bi.biWidth + padding, SEEK_CUR); Another way I tried is with SEEK_SET: fseek(inptr, (-bi.biWidth - padding) * (i + 1), SEEK_SET); The picture stays the same as when I started trying to solve it. Jun 10 '16 at 10:01
  • Finally finished it. Thanks Cliff. Jun 14 '16 at 9:55

You must log in to answer this question.

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