Suppose I want to copy an integer array to another array pointed by a
void pointer of different size.
Some thing like this is done probably in realloc function.

The problem is it is not working for me ... here's the code

#include <stdio.h>
int main(){

        int *p,i=0;
        void *x;
        p=(int *)malloc(3*sizeof(int));
        x=malloc(24);
        p[0]=1;
        p[1]=2;
        p[2]=3;
        p[3]=4;
        while(i<4){
                *((int *)x)=*p;
                ((int *)x)++;
                p++;
                i++;
        }

        for(i=0;i<4;i++){
                printf("%d\n",p[i]);
                printf("%d\n",((int *)x)[i]);
        }
        return 0;
}


Can anyone suggest what is happening wrong in this code.....or what
can be a better way to do this.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to