Hi all!!!
I am writing a program for CRC in C++ ...I want an int arrays conctaentaion i.e. i have created an array of zeros and now wanna add it to the last of an array pattern[]..how to achieve this ?The new array should be of the size newsize .
Following is the code:
Code:
// crc code.cpp : Defines the entry point for the console application.
//
#include"stdafx.h"
#include<iostream>
#include<conio.h>
#include<malloc.h>
using namespace std;
# define size len;
int main(void)
{
int message[10],i,lim_fcs,n,tot_len;
int pattern[50], msg_len,patt_len,len;
cout<<"Enter the number of bits for message length(length should be within 10 bits):"<<endl;
cin>>n;
cout<<"Enter the message to send:"<<endl;
for(i=0;i<n;i++)
{
cin>>message[i];
}
cout<<"The message to send is:"<<endl;
for(i=0;i<n;i++)
{
cout<<message[i];
cout<<"\t";
}
cout<<"\n";
msg_len=n;
cout<<"Enter the limit for FCS:"<<endl;
cin>>lim_fcs;
cout<<"Enter the number of bits for Pattern(limit to be within 10 bits)"<<endl;// pattern bits taken here
cin>>patt_len;
cout<<"Enter the pattern bits:"<<endl;
for(i=0;i<patt_len;i++)
{
cin>>pattern[i];
}
cout<<"The pattern is:\n";
for(i=0;i<patt_len;i++)
{
cout<<pattern[i];
cout<<"\t";
}
cout<<endl;
tot_len=msg_len+lim_fcs;
len=tot_len-patt_len;
int *a; //array for zeros here
a=new int[len];
for(int j=0;j<len;j++)
{
a[j]=0;
}
cout<<"The array is:\n";
for(int j=0;j<len;j++)
{
cout<< a[j];
cout<<"\t";
}
int newsize =len+patt_len;
//NEED here is an array patternnew[newsize] having elements of pattern[] followed by zeros of a[]....
getch();
return 0;
}