从char16_t *复制到char16_t *

时间:2016-12-12 22:31:58

标签: c string char16-t

我正在尝试复制传递给函数的char16_t*,但却找不到任何方法。

foo(char16_t* characters) {
    char16_t* copiedCharacters;
    //copy characters to copiedCharacters
}

我尝试使用strncopy(),但它只复制char*

2 个答案:

答案 0 :(得分:2)

有一种已知的结构(借用strcpy):

char16_t* str16cpy(char16_t* destination, const char16_t* source)
{
    char16_t* temp = destination;
    while((*temp++ = *source++) != 0)
    ;
    return destination;
}

答案 1 :(得分:-1)

只需调整strcpy implementation

即可
char16_t *mystrcpy(char16_t *dest, const char16_t *src)
{
  unsigned i;
  for (i=0; src[i] != '\0'; ++i)
    dest[i] = src[i];
  dest[i] = '\0';
  return dest;
}