Hi everyone,
I just got a problem referencing void pointer. If in my code, I replace *rbuf= &svar by (rbuf= &svar;); it does not complain but it does not return the real value (rbuf is a void pointer). Please Can anyone give me any advise. I would really apreciated
/*****************************************************/
#include <stdio.h>
#include <math.h>
int chamaleon (void *sbuf, void *rbuf, int count);
int main()
{
const int max = 512 * 512;
double sbuf[max];
double rbuf[max];
double rr;
int count=max;
int i;
for (i = 0; i < count; i++)
sbuf[i] = (i + 1) * 1.0;
chamaleon (sbuf, rbuf, count);
printf ("Value of rbuf outside function is = %g\n", *((double *)rbuf));
return 0;
}
int chamaleon (void *sbuf, void *rbuf, int count)
{
double svar = 0.0;
int i;
for(i=0;i < count;++i)
svar = svar + *((double *)sbuf + i);
*rbuf= &svar; /*** here is the problem (rbuf= &svar;) */
printf ("Value of rbuf inside function is = %g\n", svar);
return(0);
}