unsigned shot类型的数组赋值的问题

bejesus 2004-09-01 01:58:17
有两个unsigned shot类型的数组,想将一个数组的所有内容复制到另外一个数组中(不想用for循环之类的),有没有如strcpy之类的方法? 或用memset?
...全文
173 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lifeixiao 2004-09-02
  • 打赏
  • 举报
回复
unsigned short a[10],b[100];
int a_len,b_len;
a_len=sizeof(b)/sizeof(unsigned short);
b_len=sizeof(b)/sizeof(unsigned short);
bejesus 2004-09-01
  • 打赏
  • 举报
回复
谢谢!我想也是memcpy啦!

但如果这两参数都是unsigned short型数组的指针呢? 这时有什么办法能知道源数组的大小?
yanghuajia 2004-09-01
  • 打赏
  • 举报
回复
memcpy --linux
oo 2004-09-01
  • 打赏
  • 举报
回复
memcpy
kunp 2004-09-01
  • 打赏
  • 举报
回复
memcpy就可以了。看看例子:

#include <iostream>
using namespace std;

int main()
{
unsigned short s1[] = { 2, 3, 4, 5, 6, 7};
unsigned short s2[] = { 1, 1, 1, 1, 1, 1};

int ix = 0;
cout << "s1:\n";
for(ix = 0; ix < sizeof(s1)/sizeof(unsigned short); ix++)
{
cout << s1[ix] << endl;
}

cout << "s2:\n";
for(ix = 0; ix < sizeof(s1)/sizeof(unsigned short); ix++)
{
cout << s2[ix] << endl;
}

memcpy(s1, s2, sizeof(s1));

cout << "after memcpy" << endl;

cout << "s1:\n";
for(ix = 0; ix < sizeof(s1)/sizeof(unsigned short); ix++)
{
cout << s1[ix] << endl;
}

cout << "s2:\n";
for(ix = 0; ix < sizeof(s1)/sizeof(unsigned short); ix++)
{
cout << s2[ix] << endl;
}
return 0;
}

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧