Debug Assertion Failed fileread

Ioana Source
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);

Debug Assertion Failed!



             File: minkernel \crts \ ucrt \ src \ appcrt \stdio\ fgets.cpp

             Line: 33

             Expression: stream.valid()

             Abort   Retry  Ignore

That windows pops in every time i try to run my program in Visual Studio 2017. I would like to read a txt file in but this is always mess up my program. Any idea how to prevent it? (my txt file is in the same file with the source.c)



comments powered by Disqus