Copy struct to struct in C

前端 未结 7 1761
北荒
北荒 2020-11-27 14:06

I want to copy an identical struct into another and later on use it as a comparance to the first one. The thing is that my compiler gives me a warning when Im doing like thi

7条回答
  •  伪装坚强ぢ
    2020-11-27 14:45

    Your code is correct. You can also assign one directly to the other (see Joachim Pileborg's answer).

    When you later come to compare the two structs, you need to be careful to compare the structs the long way, one member at a time, instead of using memcmp; see How do you compare structs for equality in C?

提交回复
热议问题