分段故障(核心倾倒)错误未解决
Segmentation fault (core dumped) error not resolved
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
int i,n;
char * buffer=NULL;
i=0;
cout<<"enter the character length you wish to store dynamically"<<endl;
cin>>i;
buffer= (char*) malloc(i+1);
if(buffer=NULL)
exit(1);
for(n=0;n<i;++n)
buffer[n]=rand()%26+'a';
buffer[i]=' ';
cout<<"the string is "<<buffer<<endl;
free(buffer);
return 0;}
我正在得到分割错误:输出:输入您希望动态存储的角色长度5分段故障(核心倾倒)我无法弄清楚我犯的错误?我试图以调试模式运行,但是没有生成核心文件。请建议解决方案。
buffer=NULL
是一个分配。它将被评估为false,buffer[n]=rand()%26+'a';
将取消分配的NULL
。
做比较 buffer==NULL
。
相关文章:
- Visual Studio 2017 中的 QtMetaObject 未解决的外部错误
- 在Embarcadero C++ Builder中生成的DLL未解决的外部链接错误
- 函数路径追加上未解决的外部符号错误
- 尝试使用堆栈简化目录路径时出现未解决的分段错误
- C++编译错误LNK2019:未解决的外部符号错误
- VTK / ITK/ QT - 未解决的外部符号错误 (LNK2001)
- 错误LNK1120:未解决的外部
- QT创建者:简单程序未解决的外部符号和外部符号错误
- 枚举作为基类的模板参数总是会因未解决的错误而失败
- 无法确定未解决的外部错误来自何处
- 错误:LNK 2019:Visual Studio中未解决的外部符号_IMP_CRTDBGREPORTW
- 链接2001错误带有未解决的外部符号
- OpenVDB链接器错误:未解决的外部符号
- 分段故障(核心倾倒)错误未解决
- 链接器错误:未解决的外部符号
- CURL ilink32错误:未解决的外部
- 当链接到/clr DLL时,c++链接器错误(未解决的外部)
- 提升线程错误<未解决的重载函数类型>
- 链接器错误:未解决的外部符号问题
- XE5 Ansi/Unicode字符串链接器错误(未解决的外部)