我无法理解CS50底层实践问题4周的几行代码。

huangapple go评论44阅读模式
英文:

I can't understand few lines of codes CS50 bottomup practice problem 4 week

问题

I'm trying to understand the week 4 assignment (BOTTOMUP) but I'm totally lost. I understand that in order to "turn a photo upside down" you need to do the following basic steps:

  1. Open the photo
  2. Write them to the buffer
  3. Overwrite the newly created file from the buffer
  4. close old and new photo.

Everything is clear to me until:

// Read infile's BITMAPFILEHEADER

BITMAPFILEHEADER bf;

fread(&bf, sizeof(BITMAPFILEHEADER), 1, inptr);

&bf is a buffer? Can someone explain this in layman's terms?
I need to understand the basics.

英文:

I'm trying to understand the week 4 assignment (BOTTOMUP) but I'm totally lost. I understand that in order to "turn a photo upside down" you need to do the following basic steps:

  1. Open the photo
  2. Write them to the buffer
  3. Overwrite the newly created file from the buffer
  4. close old and new photo.

Everything is clear to me until:

// Read infile's BITMAPFILEHEADER

BITMAPFILEHEADER bf;

fread(&bf, sizeof(BITMAPFILEHEADER), 1, inptr);

&bf is a bufor? Can someone explain this in layman's terms?
I need to understand the basics

答案1

得分: 0

BITMAPFILEHEADER bf; 声明了一个名为 bf 的变量,它是一个 BITMAPFILEHEADER 结构体。

&bf 取该变量的地址以传递给 fread 函数。换句话说,它是指向你的 BITMAPFILEHEADER 变量的指针。该变量是 fread 函数将用文件中的数据填充的 "缓冲区"(计算机内存的一部分)。

到目前为止,这段代码仅仅读取了位图文件的头部信息,并将其存储在该结构体中。随后的代码将使用这些信息来确定图像数据的大小、像素格式和布局。

由于你的问题似乎涉及基本的 C 或 C++ 编程语言概念,我建议你在提问时为你所使用的编程语言添加相应的标签。此外,你还可以花一些时间将你的代码格式化为适合在 Stack Overflow 上发布的格式(请参考 如何格式化我的帖子?)。

英文:

BITMAPFILEHEADER bf; declares a variable named bf that is a BITMAPFILEHEADER struct.

&bf takes the address of that variable to pass to the fread function. In other words, it's a pointer to your BITMAPFILEHEADER variable. That variable is the "buffer" (a section of computer memory) that the fread function will fill with the data from the file.

This code so far simply reads the header part of the bitmap file in that structure. The code that follows will use that information to figure out the size, pixel format, and layout of the image data that follows.

Since you question appears to be about basic C or C++ programming language concepts, I recommend you tag these kinds questions with tag for the programming language you're using. Also take a moment to format your code for Stack Overflow (see How do I format my posts?)

huangapple
  • 本文由 发表于 2023年2月18日 09:05:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75490537.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定