I need help with this. Im trying to copy one array into another, one by array subscript notation and the other by pointer notation.
I keep getting the error during runtime "stack around variable array was corrupted" My JIT does not work.keeps telling me registration is incorrect so i cant use it,nor can I fix it. Anyway heres the code. any help would be appreciated.
Code:
#include <iostream>
#include <iomanip>
using namespace std;
void copy1( double *, const double * );
void copy2( double *, const double * );
int main()
{
double array[10] = { 0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 };
double array1[10] = {0.0};
double array2[10] = {0.0};
cout << fixed << setprecision(1);
copy1 ( array1, array );
cout << "array1 = " << *array1 << ' ' << endl;
copy2 ( array2, array );
cout << "array2 = " << *array2 << ' ' << endl;
return 0;
}
//copy array to array1 using array notation
void copy1( double *s1, const double *s2 )
{
for ( int i = 0; ( s1[i] = s2[i] ) != s2[10]; i++ )
;
}
//copy array to array2 using pointer notation
void copy2( double *s1, const double *s2 )
{
for ( ; ( *s1 = *s2 ) != s2[10]; s1++, s2++ )
;
}