Debug Assertion失败的文件读取

时间:2018-06-13 15:25:47

标签: c data-structures filereader

                     fvc_changes  exacerbation
Date       Time                               
2017-03-14 19:27:14         0.00              
2017-03-15 11:35:21        14.81              
2017-03-16 15:37:02         3.70              
2017-03-17 17:11:16         3.70              
2017-03-18 20:29:35         7.41              
2017-03-19 20:53:09       -12.52              
           21:53:09       -18.52              
           21:54:23       -11.11              
2017-03-20 14:36:24       -14.81              
2017-03-21 22:36:43       -22.22  EXACERBATION
2017-03-24 17:11:16         3.70              
2017-03-25 20:29:35         7.41              
2017-03-26 21:53:09       -18.52              
2017-03-27 21:54:23       -11.11              
2017-03-28 14:36:24       -14.81  EXACERBATION
2017-03-29 22:36:43       -22.22  EXACERBATION
2017-03-30 22:36:43        22.22              
2017-04-02 20:53:09       -12.52              
           21:53:09       -18.52              
           21:54:23       -11.11              
2017-04-03 14:36:24       -14.81              

Debug Assertion失败!

FILE * f;
f = fopen("Depozite.txt", "r");

char* token, file_buf[LINESIZE], sep_list[] = ",";
while (fgets(file_buf, sizeof(file_buf), f)) {
    token = strtok(file_buf, sep_list);
    tmpDepozit.idDepozit = (char*)malloc((strlen(token) + 1) * sizeof(char));
    strcpy(tmpDepozit.idDepozit, token);

    token = strtok(NULL, sep_list);
    tmpDepozit.capacitate = atoi(token);

    token = strtok(NULL, sep_list);
    tmpDepozit.nrTipuriCereale = atoi(token);

    tmpDepozit.listaCereale = (char**)malloc(tmpDepozit.nrTipuriCereale * sizeof(char*));

    for (int i = 0; i<tmpDepozit.nrTipuriCereale; i++) {
        token = strtok(NULL, sep_list);
        tmpDepozit.listaCereale[i] = (char*)malloc((strlen(token) + 1) * sizeof(char));
        strcpy(tmpDepozit.listaCereale[i], token);
    }

    token = strtok(NULL, sep_list);
    tmpDepozit.procentIncarcare = (float)atof(token);

    inserareHTable(HTable, tmpDepozit, DIM);
}

每次我尝试在Visual Studio 2017中运行我的程序时都会弹出窗口。我想读取一个txt文件,但这总是搞乱了我的程序。知道怎么预防呢? (我的txt文件与source.c在同一个文件中)

0 个答案:

没有答案