Copying arrays of structs in C

后端 未结 6 965
后悔当初
后悔当初 2021-02-06 12:03

It\'s been a long since I don\'t use C language, and this is driving me crazy. I have an array of structs, and I need to create a function which will copy one array to another (

6条回答
  •  星月不相逢
    2021-02-06 12:58

    As Johannes Weiß says, memcpy() is a good solution.

    I just want to point out that you can copy structs like normal types:

    for (i=0; i<4; i++) {
        b[i] = a[i]; /* copy the whole struct a[i] to b[i] */
    }
    

提交回复
热议问题