我在输出中得到线程1:SIGNAL sigabrt

时间:2013-07-24 06:18:52

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

这是我的代码,PLease帮助我!即时通讯使用xcode ..我想生成一个多项式的序列,这些项被xor'ed并对第一个输入位做反馈,因为它是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];
}

1 个答案:

答案 0 :(得分:0)

这里有一个超出范围的数组访问:

    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];