编程知识 cdmana.com

Today, there was a problem when I wanted to implement memcpy while learning memcpy (vs2019 I used)

The phenomenon and background of the problem

++ Lvalue required

void* my_memcpy(void* dest,const void* src,size_t num){    void* ret = dest;    assert(dest!=NULL);    assert(num!=NULL);    while (num--)    {        *(char*)dest = *(char*)src;        ++(char*)dest;        ++(char*)src;    }    return ret;}struct  s{     char name[20];     int age;};int main(){    struct s a3[20]= { {
   
   
   
   " Zhang San ", 20},{
   
   
   
   " Li Si ",21} };    struct s a4[10]= {
   
   
   
   "0"};    my_memcpy(a1, a2, sizeof(a3));    printf("%s", a4->name);    return 0;}
Operation results and error reporting contents
My solution ideas and tried methods

I created two new character arrays void The value of the pointer is placed inside to ++, But the output is ?

What I want to achieve

版权声明
本文为[CSDN Q & A]所创,转载请带上原文链接,感谢
https://cdmana.com/2021/12/20211207174202784n.html

Scroll to Top