I am getting a segmentation fault when I run this program, and am fairly sure that the problem is in the third for loop, where I try to copy the bytes from *pixel to *line, duplicating each byte 'resize' times. In the loop I have two lines of code that I tried to use to implement Zamyla's array method, but both resulted in seg faults. Any ideas on what's happening? Thanks.
// storage of bytes-to-write
RGBTRIPLE* line = malloc(bi.biWidth * sizeof(RGBTRIPLE));
// iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight / resize; i++)
{
// iterate over pixels in scanline
for (int j = 0; j < bi.biWidth / resize; j++)
{
// read RGB triple from infile
// storage of bytes read
RGBTRIPLE* pixel = malloc(sizeof(RGBTRIPLE));
fread(pixel, sizeof(RGBTRIPLE), 1, inptr);
fseek(inptr, padding, SEEK_CUR);
//copying bytes read (stored in *pixel) to bytes-to-write (stored in *line)
for (int k = 0; k < resize; k++)
{
//memcpy(line + (j * resize + k) * sizeof(RGBTRIPLE), pixel, sizeof(RGBTRIPLE));
//*(line + (j * resize + k) * sizeof(RGBTRIPLE)) = *pixel;
}
free(pixel);
}
...