如题

解决方案 »

  1.   

    为什么不能用memcpy将一个unsigned char[10]的内容拷贝到unsigned char*中? 
    --答案:你程序写错了。
      

  2.   

    楼上的回答真坏哦你用unsigned char 数组吧估计你是直接拿一个指针放进去做操作的吧
      

  3.   

    我的代码如下:
    char* Msg_Id;
    unsigned char[10] Content;
    memcpy(Msg_Id, Content, sizeof(Content);  <---这一句代码就会运行出错。
      

  4.   

    我的代码如下:
    char* Msg_Id;
    unsigned char[10] Content;
    memcpy(Msg_Id, Content, sizeof(Content);  <---这一句代码就会运行出错。你的char* Msg_Id;只是个指针没有空间来放你要放的东西
    所以你可以
    1   char Msg_Id[10];
    2   char*Msg_Id;
        Msg_Id=(char*)malloc(10);
        ...
        free(Msg_Id);
    用完要free的
      

  5.   

    char* Msg_Id; // 没有分配内存!
    unsigned char[10] Content;
    memcpy(Msg_Id, Content, sizeof(Content);
      

  6.   

    Msg_Id在使用前应该先指向块有效的空间
    譬如:
    char* Msg_Id;
    unsigned char[10] Content;
    char  buf[10];
    Msg_Id=buf;
    memcpy(Msg_Id, Content, sizeof(Content);
      

  7.   

    谢谢各位大哥指点迷津了。
    不过说的方法都是Msg_Id有固定的长度的,如果没有固定长度怎么处理呢?如果分配太长的空间又比较浪费
      

  8.   

    这样写:
    char* Msg_Id;
    Msg_Id=new char[10];
    unsigned char[10] Content;
    memcpy(Msg_Id, Content, sizeof(Content); 
      

  9.   

    用new来分配就可以了不过记得要delete这样的话,你要多大就分配多大咯