gpt4 book ai didi

c - 如何从C中的文件中读取一行

转载 作者:太空狗 更新时间:2023-10-29 14:55:04 26 4
gpt4 key购买 nike

<分区>

我想逐行读取文件中的行,但它对我不起作用。

这是我尝试做的:

FILE *file;
char *line = NULL;
int len = 0;
char read;
file=fopen(argv[1], "r");

if (file == NULL)
return 1;

while ((read = getline(&line, len, file)) != -1) {
printf("Retrieved line of length %s :\n", &read);
printf("%s", line);
}

if (line)
free(line);

return 0;

有什么建议为什么不起作用吗?

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