他们俩都可以从流中得到一条线。
定义如下:
ssize_t
getline(char ** restrict linep, size_t * restrict linecapp, FILE * restrict stream);
和
char *
fgets(char * restrict str, int size, FILE * restrict stream);
为什么getline
需要a pointer to a pointer to char
,而不是a pointer to char
像什么一样使用fgets
呢?
下面的两个表达式是否等价?</p>
(1)
char *str = NULL
read = getline (&str, &len, fp);
(2)
char *str = NULL
read = fgets (str, &len, fp);