C:Getline不会读取完整的文档
我需要在带有getline的大XML文件中编写C读取程序,问题只有大约30亿行的2085。在以下代码中,问题发生。
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main()
{
size_t l = 0;
char *line;
line = NULL;
while (getline(&line,&l,stdin)>0) {
getline(&line,&l,stdin);
printf("%s\n", line);
printf("%i\n", i);
free(line);
line = NULL;
}
return 0;
}
我的第一个目标是用printf显示线条,以便我可以使用。 2080年直到2090年的行都不是空的。 如果我将循环条件更改为&gt; = 0约80.000,并且如果我将printf评论为130.00行。但是相反,我会遇到一个细分错误。在这种情况下,我真的不知道该如何解决。 我正在使用Visual Studio代码编辑和Mysys2 mingw在Windows 11上运行代码。 首先找不到getline函数,我通过复制将这个页面,因为#include头球似乎不起作用。
I need to write a program in C reading in a big XML file with getline, the problem is only 2085 of the approxemately 3 billion lines are read. In the following code the problem occurs.
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main()
{
size_t l = 0;
char *line;
line = NULL;
while (getline(&line,&l,stdin)>0) {
getline(&line,&l,stdin);
printf("%s\n", line);
printf("%i\n", i);
free(line);
line = NULL;
}
return 0;
}
My first goal would be to display the lines, with printf so I can work with that.
Neither line from 2080 til 2090 is empty.
If I change the loop-condition to >=0 about 80.000 are read in and if I comment the printf out, about 130.00 lines. But instead I get an segmentation error. Which I really don't know how to solve in this case.
I am using Visual Studio Code to edit and MYSYS2 MinGW to run the Code, on Windows 11.
First the getline Function couldn't be found, I resolved it by Copy-Pasting the getline Code of this page, because the #include header's seemed not to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
中的行时,您会跳过每一行,而
则在中再次阅读,然后在当时的身体中再次读取它,while
then you read it again in the while body