【发布时间】:2022-01-05 01:08:11
【问题描述】:
下面的这个函数在fgets 语句中终止并给出了一个分段错误,我不知道为什么:
const char* display_exp(FILE* fp){
char maxstr[50];
char* temp;
char* exp;
fgets(maxstr,sizeof(maxstr),fp);
exp = (char*)calloc(strlen(maxstr),sizeof(char));
temp=maxstr;
free(temp);
printf("%s",exp);
return exp;
}
【问题讨论】:
标签: c segmentation-fault dynamic-memory-allocation free fgets