gpt4 book ai didi

c - 回复 : Reading a line and using realloc in C

转载 作者:太空宇宙 更新时间:2023-11-04 08:11:30 26 4
gpt4 key购买 nike

所以我浏览了一些相同的问题并找到了有效的答案。我只是想知道是否有人可以向我解释这个答案中代码的最后一行:

Read text from a file and realloc when needed

fgets(linebuffer + (maxlinelen/2 - 1), maxlinelen/2 + 1, fp); //this line

非常感谢!

最佳答案

编写器正在尝试读入数组的后半部分。为此,基地址必须更高。因此第一个参数 linebuffer + (maxlinelen/2 - 1)。它获取数组的基地址,并将数组长度的一半添加到它。

但是由于数组只有一半长,作者将数组的大小减半。因此第二个参数 maxlinelen/2 + 1

enter image description here

关于c - 回复 : Reading a line and using realloc in C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39039162/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com