我正在尝试通过 iTunes 大学/哈佛 CS50 课程自学 C。在其中将编写一个程序来调整位图图像文件的大小。为此,我定义了一个数组(缓冲区)并编写了程序运行所需的代码——它确实有效。但是,我不得不作弊并用谷歌搜索答案,因为我无法弄清楚,而且我不理解解决方案中的特定语法,希望有人能提供帮助。
代码块如下所示,我在评论中添加了我的具体困惑点:
// allocate array to hold scanline pixels - this is the array I define
RGBTRIPLE *buffer = malloc(bi.biWidth * sizeof(RGBTRIPLE));
// declare variable to track position in buffer array
int count;
// iterate over infile's scanlines
for (int i = 0, height = abs(oldHeight); i < height; i++)
{
// initialize count var to 0
count = 0;
// iterate over pixels in scanline
for (int j = 0; j < oldWidth; j++)
{
// temporary storage
RGBTRIPLE triple;
// read RGB triple from infile
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
// place pixel in buffer array n times
for (int k = 0; k < n; k++)
{
// below is the confusion. Some sudo code would be great!
*(buffer+(count)) = triple;
count++;
}
}