CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  C语言

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

楼主bejesus(天塌下来)2004-09-01 13:58:17 在 C/C++ / C语言 提问

有两个unsigned   shot类型的数组,想将一个数组的所有内容复制到另外一个数组中(不想用for循环之类的),有没有如strcpy之类的方法?   或用memset? 问题点数:30、回复次数:5Top

1 楼kunp(一天一小步)回复于 2004-09-01 14:07:21 得分 20

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;  
  }Top

2 楼oo(为了名副其实,努力学习oo技术ing)回复于 2004-09-01 14:07:25 得分 5

memcpyTop

3 楼yanghuajia(我要抢分)回复于 2004-09-01 14:09:49 得分 0

memcpy                   --linux  
  Top

4 楼bejesus(天塌下来)回复于 2004-09-01 14:26:56 得分 0

谢谢!我想也是memcpy啦!  
   
  但如果这两参数都是unsigned   short型数组的指针呢?   这时有什么办法能知道源数组的大小?Top

5 楼lifeixiao(李飞笑)回复于 2004-09-02 16:10:52 得分 5

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);  
  Top

相关问题

  • 数组赋值
  • 数组赋值!
  • 急!!!数组赋值
  • 数组赋值问题
  • 为数组赋值出错!
  • 怎样对数组赋值???
  • 关于数组赋值
  • 二维数组赋值
  • 数组赋值问题
  • 实型数组的赋值

关键词

  • 数组
  • shot类型
  • unsigned
  • short s

得分解答快速导航

  • 帖主:bejesus
  • kunp
  • oo
  • lifeixiao

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo