Copy struct into char array

前端 未结 6 2008
面向向阳花
面向向阳花 2020-12-31 15:41

I am learning C and have a question about structs.

I have a

struct myStruct {
    char member1[16];
    char member2[10];
    char member3[4];
};         


        
6条回答
  •  醉梦人生
    2020-12-31 16:10

    Pretty simple with memcpy.

    char foo[30];
    struct myStruct s;
    
    s.member1 = //some data
    s.member2 = //some data
    s.member3 = //some data
    
    memcpy(foo, &s, 30);
    

提交回复
热议问题