I implemented a generic quick sort and now I want to accept the array from command line. Following is a function that is supposed to copy character pointers from array argv to base. I am getting segmentation fault. The copy is working fine when I pass address of two integers.
#include<stdio.h>
void copy(void *src, void *dest, int size)
{
char *s, *d;
int i;
s = src;
d = dest;
for(i = 0; i < size; i++)
d[i] = s[i];
}
int main(int argc, char *argv[])
{
void *base;
int i = 10;
int j = 20;
printf("%d, %d\n", i, j);
copy(&i, &j, sizeof(int));
printf("%d, %d\n", i, j);
copy(argv, base, sizeof(char *));
return 0;
}
Output
10, 20
10, 10
Segmentation fault (core dumped)