他们两个都可以从流中获得一条线。
定义如下:
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
?
以下两个表达式是否相同?
(1)
char *str = NULL
read = getline (&str, &len, fp);
(2)
char *str = NULL
read = fgets (str, &len, fp);