C语言读取2700万行法国地址CSV触发链表损坏核心转储报错求助
海量地址数据加载统计程序运行崩溃问题
项目基本情况
- 核心目标:从文件加载海量地址数据,将指定行数的地址数据输出到终端,统计对应规模下的展示耗时,将每轮测试的行数与对应耗时写入独立CSV统计文件,最终生成展示耗时随显示行数变化趋势的分析曲线
- 数据基础:源文件
france.csv共包含2700万行地址数据,通过循环逻辑控制每轮测试需要输出的行数,覆盖多梯度的行数测试场景 - 运行异常:程序执行过程中抛出
unsorted double linked list corrupted Aborted (core dumped)报错,触发核心转储直接终止运行
当前实现代码
#include<stdio.h> #include<stdlib.h> #include<string.h> #include <time.h> typedef char string [50]; typedef struct adresse{ int zip_code; string city; } adresse Fr[27381996];// I will upload data to this table from the file int main (){ int i=-1, line_nb=1; int j=1; double timing=0.0;//This is for calculating the timing //These upcoming lines are for opening the file FILE * France_adr; France_adr=fopen("france.csv","r"); char adr[300]; for(line_nb=1;line_nb<10;line_nb++) { time_t begin= time(NULL);//Here I start the timing while((!feof(France_adr))&& (i<line_nb)) { fgets(adr,300,France_adr); char* s = strdup(adr); char* val = strsep(&s,","); /* This is because in the file there are some data that I don't want to use and they are separated with a comma*/ while(val!=NULL) { val=strsep(&s,","); // This is also to sort the data I want to get into my // table if(j==2 && i!=-1) { Fr[i].zip_code=atoi(val); printf("%d | ",Fr[i].zip_code); } j++; } i++; j=1; printf("\n"); } fclose(France_adr); printf("\n\n"); time_t end = time(NULL); duree += (double)(1000*(end-begin)); //This section is for writing the timing and number of lines into a new // file FILE * donnee_t; donnee_t=fopen("Affichage_Donnee_Courbe.csv","a"); fprintf(donnee_t,"\n %d,%f",i,duree); fclose(donnee_t); i=0; } return 0; }
内容的提问来源于stack exchange,提问作者benkadourr fatima
相关产品推荐
相关产品推荐

