The first argument of the strcpy
call is not a modifiable array of char
, it is the array of char*
, producing a type mismatch and unexpected behavior.
Modifying the code to strcpy(message[0], "Copy")
would cause another problem as you would be trying to modify the string literal "Hello!000000000000"
to which message[0]
points.
If you just wish to modify the array element, just use a simple assignment to change the pointer:
char *message[10] = { "Hello!000000000000", "Good Bye!", "1202", "hel", "beh", "cheshm" };
char *dst = "Copy";
message[0] = "Copy";
printf("%s", message[0]);
Note that message
is not a 3 dimensional array. It is an array of pointers to char
. You could define it as an actual 2D array with the same initializer and the contents would be modifiable:
char message[10][20] = { "Hello!000000000000", "Good Bye!", "1202", "hel", "beh", "cheshm" };
char *dst = "Copy";
strcpy(&(message[0]), "Copy");
printf("%s", message[0]);