开发者

store object in an array using ansi c?

开发者 https://www.devze.com 2023-01-15 11:37 出处:网络
I make a structure just like struct abc { //any function or variable } obje[20]; now I want that the each object of 开发者_JAVA百科abc store in array. means that arr[0] contain obj[0] only; can it

I make a structure just like

struct abc {
    //any function or variable
} obje[20];

now I want that the each object of 开发者_JAVA百科abc store in array. means that arr[0] contain obj[0] only; can it is possible. if it is possible then some one help me in this matter.


If you want to copy the objects from the array obje into the array arr, you can use memcpy() from <string.h>:

#include <string.h>

struct abc arr[20];

memcpy(&arr, &obje, sizeof arr);

/* Now arr[0] has a copy of obje[0], arr[1] has a copy of obje[1], ... */
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号