Originally Posted by
Lired
Then please explain me where im thinking wrong thats what im asking. it works with every example you said so please explain a specific example where it doesnt, untill now i havent seen a single example where it doesnt.
in post 16 and 18 you said it was broken because the pointers could point to diferent objects, so i ask if both arrays are strings then it works because they are of the same type.
Same object and same type are not equivalent. For example, int x, y; declares two ints. They are both the same type, but are not the same actual object. Similarly
Code:
char foo[100];
char bar[100];
foo and bar are not the same object. If you pass them to your function and try to subtract them, it results in undefined behavior. Undefined behavior is bad. Read these two links:
Question 11.33
LLVM Project Blog: What Every C Programmer Should Know About Undefined Behavior #1/3
Just because it seems to work doesn't mean it's a good idea. You're simply getting lucky.
Originally Posted by
Lired
Also the second code i cant see where it's wrong, the source string can't be too big, but no word is that big to make it a problem so i think it is ok too.
We're telling you that it is wrong. If you don't want to listen to us because it doesn't look wrong to you (even though you are a novice), then why even come here asking for help? And for the last bloody time, you need to test thoroughly. You should try to break your function. If you can't in any way break it, and it meets all the requirements, then you were successful. If you don't believe me that it's broken, try this:
Code:
char foo[10] = "short";
char bar[40] = "supercalifragilisticexpialidocious";
movefunction(foo, bar, 100); // feel free to try a shorter number like 20
printf("foo = %s\n", foo);
printf("bar = %s\n", bar);
Does the output look right to you?