0

My program works fine visually but fails in check50.newpadding is outfile's padding and oldpadding is infile's padding.

for (int i = 0, biHeight = abs(oldHeight); i < biHeight; i++)
{
// temporary storage
RGBTRIPLE triple;
//copy each line n time(s) to the outfile
for( int m = 0 ; m < n ; m++ )
{
    //copy and resize the first line from infile to outfile
    for( int j = 0 ; j < oldWidth ; j++ )
    {
        // read RGB triple from infile
        fread(&triple, sizeof(RGBTRIPLE), 1, inptr);

        // write a RBG triple n times to outfile
        for( int k = 0 ; k < n ; k++ )
        {
            fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
        }
    }

    // adding padding for outfile if any
    for( int l = 0 ; l < newpadding ; l++ )
    {
        fputc( 0x00 , outptr ) ;
    }
    //go back to the first of the line in infile
    fseek(inptr , -(oldWidth* sizeof(RGBTRIPLE)) , SEEK_CUR ) ;
}
fseek(inptr , oldWidth* sizeof(RGBTRIPLE) + oldpadding , SEEK_CUR ) ;

}
1

So biHeight is new height? Should be old height.

Also, the fseeks would need to use oldWidth*sizeof(RGBTRIPLE).

4
  • with that changed works fine but fails in chek50
    – Pegi
    Nov 17 '17 at 21:48
  • Have you compared output of your programme with output of staff solution? For example, have you updated four fields in total in the headers? The image would probably display right if only a few fields are wrong. If file size differs, the mistake is most likely in the recopy part instead.
    – Blauelf
    Nov 17 '17 at 23:21
  • More importantly, have you compared the output DATA, or even looked at the raw output data of your program with peek and xxd or did you just look at the output image using the image viewer?
    – Cliff B
    Nov 18 '17 at 2:33
  • the only problem was forgetting abs() for height in one part of the code thanks for your help ;)
    – Pegi
    Nov 18 '17 at 20:55

You must log in to answer this question.

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