问题
I am trying to free up char* acc at the end of this code:
while (fgets(line, 300, fp)!=NULL)
{
char *tmp = strdup(line);
char *acc = (char*) getfield(tmp, 2);
//check if account number already exists
if (acc != NULL){
if ((atoi(acc))== accNum){
return 1;
}
}
free(tmp);
free(acc);
}
getfield returns a const char* so I have casted it to char*, but an error arises from the pointer when I try to free() saying free(): invalid pointer. What am I doing wrong? Any help would be appreciated
来源:https://stackoverflow.com/questions/60685212/free-pointer-error-while-casting-from-const-char