ireon
Junior Member level 2
I should write a function that returns a two-dimensional array. I used a dinamic allocation of memory:
This code works if I call individually function1 or function2, but if I call both the functions it doesn't work and the result is wrong. How could I resolve the problem? Could I use an other method to return a two-dimensional array?
Code:
#include <iostream>
#include "imagine.h"
#include "function1"
#include "functrion2"
using namespace std;
int main()
{
int s = 3;
int m=(sizeof(*A)/4);
int n=(sizeof(A)/4)/m;
int*matrix=NULL;
int*v=NULL;
int*v1=NULL;
matrix=(int*)calloc(n*m,sizeof(int));
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
*(matrix+i*m+j)=A[i][j];
}
}
a=&(A[0][0]);
v=function1(a,n,m,s);
v1=function2(v,n,m,s);
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
A[i][j]=*(v1+i*m+j);
}
}
return 0;
}
This code works if I call individually function1 or function2, but if I call both the functions it doesn't work and the result is wrong. How could I resolve the problem? Could I use an other method to return a two-dimensional array?