0

I am attempting to implement the "rewrite" method of vertical scaling in pset 4's resize problem. I declare an array of RBTTRIPLE's in which I want to construct the outfile scanlines. When I try to fwrite to this array an RGBTRIPLE that I have read from the infile, I get this error:

    error: incompatible pointer types passing 'RGBTRIPLE [bi.biWidth * sizeof(RGBTRIPLE)]' to parameter of type 'FILE *'
      (aka 'struct _IO_FILE *') [-Werror,-Wincompatible-pointer-types]
                fwrite(&triple, sizeof(RGBTRIPLE), 1, out_row);
                                                      ^~~~~~~
/usr/include/stdio.h:716:38: note: passing argument to parameter '__s' here
                      size_t __n, FILE *__restrict __s);

Can I not use the fwrite function to add to an array of RGBTRIPLE's? Is bracket notation the only way to add each newly-read RGBTTRIPLE to my array?

Here is the relevant code:

for (int i = 0, biHeight = abs(in_biHeight); i < biHeight; i++)
{
    // array for constructing outfile scanlines
    RGBTRIPLE out_row[bi.biWidth];
    // iterate over pixels in scanline, adding to array resize_factor times
    for (int j = 0; j < in_biWidth; j++)
    {
        // temporary storage
        RGBTRIPLE triple;

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

        // print RGB triple to buffer resize_factor times
        for (int k = 0; k < resize_factor; k++)
        {
            fwrite(&triple, sizeof(RGBTRIPLE), 1, out_row);
        }
    }
0
0

"Can I not use the fwrite function to add to an array of RGBTRIPLE's? Is bracket notation the only way to add each newly-read RGBTTRIPLE to my array? "

No, you can't and bracket notation is probably the easiest.

The fwrite() function writes data to files, not arrays.

You also need to be careful to write the data to the correct positions and not overwrite the data from the previous loop.

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

You must log in to answer this question.

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