C语言 复制无符号字符数组

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4507203/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 07:23:46  来源:igfitidea点击:

Copy unsigned char array

cstringstrcpyunsigned-char

提问by user2829

What would be the best way to copy unsigned char array to another?

将无符号字符数组复制到另一个数组的最佳方法是什么?

For example:

例如:

unsigned char q[1000];
unsigned char p[1000];

strcpy (q,&p);

The above code does not work, it gives me error saying "cannot convert parameter 1 from unsigned char [1000] to char *".

上面的代码不起作用,它给我错误提示“无法将参数 1 从无符号字符 [1000] 转换为字符 *”。

回答by icecrime

As indicated by its name, strcpyworks on C string (which a unsigned char array is not).

正如其名称所示,strcpy适用于 C 字符串(无符号字符数组不是)。

You should consider memcpy.

你应该考虑memcpy