【问题标题】:I am getting thread1:SIGNAL sigbart in output我在输出中得到线程 1:SIGNAL sigabrt
【发布时间】:2013-07-23 11:44:24
【问题描述】:

这是我的代码,请帮助我!我正在使用 xcode .. 我想为多项式生成一个序列,并且这些项被异或并反馈到第一个输入位,因为它是 8 位,它完成了 2^8-1 次。备用代码也将是有帮助 提前谢谢

#include "32bit.h"
#include<iostream>

using namespace std;
int main()
{
    bool input[8];
    int n;
    bool out=0;
    cout<<"Enter the no of terms ";
    cin>>n;
    int temp1[n];
    int gen=0;
    bool store[255];
    cout<<"Input power of x in increasing order, Omit x^0";


    for(int i=0;i<n;i++)
        cin>>temp1[i];
    cout<<"Enter key to generate ";
    cin>>gen;
    for(int m=0;m<255;m++)
    {
        store[m]=input[gen];
        bool temp2[n];
        int var=0;
        for(int j=0;j<n;j++)
        {

            var=temp1[j];
            temp2[j]=input[var];
        }
        int c=0;
        for(int k=0;k<n;k++)
        {
            if(temp2[k]%2==1)
                c++;

        }
        if(c%2==1)
            out=1;
        else
            out=0;
        for(int l=0;l<8;l++)
            input[l+1]=input[l];
        input[0]=out;
    }
    for(int p=0;p<255;p++)
        cout<<store[p];
}

【问题讨论】:

  • 在调试模式下运行会发生什么?调试器在哪一行停止?
  • 在最后一行代码

标签: c++ binary xcode4.2 generator sequence


【解决方案1】:

这里有一个越界的数组访问:

    for(int l=0;l<8;l++)
        input[l+1]=input[l];

因为input 的大小仅为 8,而您正试图在此循环的最后一次迭代中写入 input[8](即不存在的第 9 个元素)。我猜应该是:

    for(int l=0;l<7;l++)
        input[l+1]=input[l];

【讨论】:

  • 谢谢,但这并没有纠正它。我有一个疑问.. 我们可以做 cin>>n;布尔温度[n];在 C++ 中 .. 还是我们必须动态地做?
猜你喜欢
  • 1970-01-01
  • 2018-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-08
  • 2018-01-23
  • 2011-12-26
相关资源
最近更新 更多