1

This seems to be a great place. My question is, what value (or how many bytes) am I moving in this implementaion of memmove()?

int main ()
{
char str[] = "memmove can be very useful......";
memmove (str+15,str+20,/*?*/);
puts (str);
return 0;
}

In the next example it says I am moving 11 bytes. But what makes it 11 bytes? Could somebody explain?

int main ()
{
char str[] = "memmove can be very useful......";
memmove (str+20,str+15,11); //source and destination are reversed
puts (str);
return 0;
}

Thanks!

Edit: BTW, the string length is 33 including the terminating null character.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
Mike mmm
  • 19
  • 3
  • 1
    `int main()` should be `int main(void)`. More important, you need `#include ` and `#include `. If your compiler didn't warn you about this, crank up its warning level until it does. – Keith Thompson Oct 29 '11 at 02:24
  • What you're showing us isn't an "implementation of memmove()", it's merely a program that calls `memmove()`. An *implementation* of `memmove()` would be the code in the runtime library that actually copies the bytes. – Keith Thompson Oct 29 '11 at 02:25
  • The 11 makes it 11 bytes. Duh. In the first example you are not moving anything until you put a number in place of /*?*/. Are you confusing memmove with strcpy? – Jim Rhodes Oct 29 '11 at 02:50

3 Answers3

1

The third parameter of memmove specifies the number of bytes to move, so in your second example you are moving 11 bytes. Your first example should not compile because you will have a syntax error on the line that calls memmove.

David Grayson
  • 84,103
  • 24
  • 152
  • 189
0

The final argument to memmove() is the number of bytes to move - in this case 11

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
Martin Beckett
  • 94,801
  • 28
  • 188
  • 263
0

Third parameter defines how many bytes to copy; in the first example you should be defining how many bytes to copy.

Suroot
  • 4,315
  • 1
  • 22
  • 28