c - 如何解决分段故障?
问题描述
调用此函数时出现分段错误错误
pterm *readterm()
{
pterm *node;
int exp;
int coeff;
printf("\nEnter exponent:");
scanf("%d",&exp);
printf("\nEnter exponent:");
scanf("%d",&coeff);
node=getnode();
node->prev=NULL;
node->exp=exp;
node->coeff=coeff;
node->next=NULL;
return node;
}
解决方案
分段错误是由于访问“不属于你”的内存而导致的一种特定错误。这意味着如果你想在pterm *node
这段代码中使用指针,你应该从内存中为指针占用空间。
据我所知,问题将出在函数上,getnode()
因为如果它是正确的,那么内存就不会有任何问题。
推荐阅读
- amazon-web-services - IAM 用户有权访问 S3 存储桶,如何从 Lambda 访问它?
- flutter - 导航器中未定义的名称“上下文”
- delphi - 将一组转换为整数
- react-native - React-Native ScrollView 与自定义起始位置的中心对齐
- java - 无法理解这个字谜问题解决方案背后的逻辑
- ios - UINavigationItem 中带有异步加载图像的按钮作为titleView
- ffmpeg - ffmpeg 使用不同的顶部和底部栏背景颜色设置填充
- python-3.x - memoryview和bytestring的优势
- android - 缩放视图隐藏内容
- powershell - 如何将 foreach-object 输出传递给接受管道输入的函数?