Re: [AD] Unicode again

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


> I may miss something, but the behaviour of the ANSI strncpy() is rather
odd,
> given that memcpy() does a very similar job.

It is not that odd, since if strncpy detects a \0 before copied 'n'
characters, it will
fills with \0 the rest of the string, iow, this program:

#include <string.h>
#include <stdio.h>

void main(void) {
  char str1[] = "hello\0everybody\0";
  char str2[] = "aaaaaaaaaaaaaaaaaa";

  strncpy(str2, str1, 10);
  // now str2 is "hello\0\0\0\0\0aaaaaaaa";

  printf("%s %d %c\n", str2, str2[6], str2[6]);

  memcpy(str2, str1, 10);
  // now srt2 is "hello\0everaaaaaaaa";

  printf("%s %d %c\n", str2, str2[6], str2[6]);
}

will print:
hello 0
hello 101 e




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/