M
Matt Kowalczyk
How come this function doesn't work?
void shift(char** list, int index) {
char buff = (*list)[0];
memmove((*list)+1, *list, index);
(*list)[0] = buff;
return;
}
I call it like so:
char* t = "abcde";
shift(&t, 1);
I expect t = "bacde"
or
shift(&t, 0) would not effect t at all.
Anyway, I made it work by creating another character array inside the function.
I then did a memcpy to copy list to this temp buffer and the memmove function
worked correctly when I passed in the temp buffer local to the function. I
would like to understand why the above code will not work. Am I doing something
wrong?
Thanks,
Matt
void shift(char** list, int index) {
char buff = (*list)[0];
memmove((*list)+1, *list, index);
(*list)[0] = buff;
return;
}
I call it like so:
char* t = "abcde";
shift(&t, 1);
I expect t = "bacde"
or
shift(&t, 0) would not effect t at all.
Anyway, I made it work by creating another character array inside the function.
I then did a memcpy to copy list to this temp buffer and the memmove function
worked correctly when I passed in the temp buffer local to the function. I
would like to understand why the above code will not work. Am I doing something
wrong?
Thanks,
Matt