提问人:Kalyan Sreekar 提问时间:2/7/2022 更新时间:2/7/2022 访问量:1060
free(): 无效指针 在 fclose() 处中止(核心转储);
free(): invalid pointer Aborted (core dumped) at fclose();
问:
我尝试调用此函数两次,当我第二次调用它时,它在打印行和 clm 后给了我这个错误
void datasize(char fl_name[], int* rw, int* clm)
{
FILE* fl;
fl = fopen(fl_name, "r+");
char fldata[100];
int i = 0, il;
int j = 0, jl = 0;
if (fl==NULL)
{
printf("%s doesnot exists in the current folder (folder of the executable)\n",fl_name);
}
while (fgets(fldata, 100, fl))
{
if (fldata[0] > 47 && fldata[0] < 60)
{
j = 0;
char* tokn = strtok(fldata, ",");
while (tokn)
{
if (((tokn[0] > 47) && (tokn[0] < 60)) || tokn[0] == '-')
{
j++;
}
tokn = strtok(NULL, ",");
}
jl = (j > jl) ? j : jl;
while (j <= jl)
{
j++;
}
i++;
}
}
il = i;
*rw = il;
*clm = jl;
printf("\n");
printf("row : %d clm : %d", il, jl);
printf("\n");
fclose(fl);
}
输出:
Reading Line Data.....
row : 20 clm : 7
Done
Reading Bus Data.....
row : 14 clm : 9
free(): invalid pointer
Aborted (core dumped)
Reading Data 和 Done 之间的部分具有函数调用。我们可以看到它打印了行和 clm,但它在 fclose() 处给出了这个错误;
如果有人引导我朝着正确的方向前进,我将不胜感激。谢谢。
答: 暂无答案
评论
return;
if (f1 == NULL) { ...
fclose
NULL
main
fl
fclose