Copy struct into char array

前端 未结 6 2010
面向向阳花
面向向阳花 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 15:52

    you could do the following if you have a myStruct variable named st:

    strcpy(foo, st.member1);
    strcat(foo, st.member2);
    strcat(foo, st.member3);
    

提交回复
热议问题