if I would call the strcpy function like this:
char *s = NULL;
strcpy(&s, "Test");
in the main function, would this be the best implementation of it: or there is a better way to implement the function? Thank you!
if I would call the strcpy function like this:
char *s = NULL;
strcpy(&s, "Test");
in the main function, would this be the best implementation of it: or there is a better way to implement the function? Thank you!
First of all: if you take
sizeof(src)
you will alloc memory for a pointer, not for a string. In 32 bit environments, this will leave you with 4 bytes of memory, and not 10 as you need.Therefore, you need to supply how much memory do you need, or infere it from your second argument: something like this: