locked
A very simple C question RRS feed

  • Question

  • Hi guys ,

     

    Please help me with a very simple (apparently not for me) issue : I have the following code and it doesn't work (it puts not correct values into result).

     

    double *input;

    double result[4];

    input=new double[4];

    input[0] = 1 ;
    input[1] = 2 ;
    input[2] = 3 ;
    input[3] = 4 ;

    memcpy(result,input,sizeof(input));

     

    Bassicaly my question is - how to copy an array that was created durring the run of the software (because the size of the array is determined in the proccess) into a place of memory I have a pointer to (in this case I chose another array just for convinience) .

    The problem is that I have to use something like memcpy since copying it in a for loop takes to much time (and crashes my software) .

     

    Thanks in advance

    Saturday, January 7, 2006 12:07 PM

Answers

  • Since the result of sizeof(double *)(notice that the type of input is double *) is always 4, you should use sizeof(result) instead.
    Saturday, January 7, 2006 1:55 PM