Hello, I need to allocate memory dynamically for arrays in FUNCTIONs
(Here for R), but I can not use that memory in my main function
Thank you so much
typedef float MYFLOAT;
// or Called Standalone
#define MYPRINT printf
#define MYMAIN main
#include <string>
#include <cstdio>
#include <cctype>
#include <stdio.h>
#include <stdlib.h>
void MAKE(MYFLOAT *R)
{
MYFLOAT RI[]={-1,4,3.34,4.78,5.23};
R=new MYFLOAT [5];
for(int i=0;i<5;i++)
R[ i ]=RI[ i ];
MYPRINT("R: %f %f\n",R[0],R[4]);
}
int MYMAIN()
{
MYFLOAT *R;
MAKE(R);
MYPRINT("RI: %f %f\n",RI[0],RI[4]);
MYPRINT("R: %f %f\n",R[0],R[4]);
// Memory Release
delete []R;
// Outputs
return 1;
}
<< moderator edit: added code tags: [code][/code] and other cleanup >>