Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct s1_ {
- int x,y,z;
- } tmp_type;
- typedef struct s2_ {
- tmp_type* p1;
- char a;
- } tmp_data;
- typedef struct s3_ {
- tmp_data* v1;
- int num;
- } tmp_list;
- void get_copy(tmp_list *list) {
- tmp_data tmp[10];
- int i;
- for(i=0;i<10;i++){
- tmp[i].p1= calloc(1,sizeof(tmp_type));
- tmp[i].p1->x = tmp[i].p1->y = tmp[i].p1->z = 6;
- tmp[i].a = 'a'+i;
- }
- list->num = 5;
- list->v1 = calloc(5,sizeof(tmp_data));
- for(i=0;i<5;i++) {
- list->v1[i].p1 = calloc(1,sizeof(tmp_type));
- }
- memcpy(list->v1,tmp,5*sizeof(tmp_data));
- for(i=5;i<10;i++) {
- // memcpy((list->v1[i].p1), (tmp[i].p1), sizeof(tmp_type));
- // list->v1[i].a=tmp[i].a;
- free(tmp[i].p1);
- }
- }
- void main()
- {
- tmp_list l1;
- int i;
- get_copy(&l1);
- for (i=0;i<l1.num;i++) {
- printf("list: %c %d %d %d\n",
- l1.v1[i].a,
- l1.v1[i].p1->x,
- l1.v1[i].p1->y,
- l1.v1[i].p1->z);
- }
- for(i=0;i<l1.num;i++){
- free(l1.v1[i].p1);
- }
- free(l1.v1);
- }
Advertisement
Add Comment
Please, Sign In to add comment