[ create a new paste ] login | about

Link: http://codepad.org/VDC8hvKu    [ raw code | output | fork ]

C, pasted on Sep 6:
#include <stdio.h>
#include <stdlib.h>

struct A{
  int a;
  int b;
};

struct B{
  int b;
  int c;
  struct A AAA;
};


void inin(struct A *test_A)
{
  int i;
  for(i=0;i<2;i++){
  test_A[i].a = 1000+i;
  test_A[i].b = 1001+i;
  }
}

int main(int argc,char** argv)
{
  struct B *test_B;
  struct A *test_A;
  
  test_B = malloc(2*sizeof(struct B)); 
  test_A = malloc(2*sizeof(struct A)); 

  int i;
  for(i=0;i<2;i++){
  test_A[i].a = 2+i;
  test_A[i].b = 3+i;

  test_B[i].b = 101+i;
  test_B[i].c = 102+i;
  test_B[i].AAA.a = 103+i;
  test_B[i].AAA.b = 104+i;
  }

  printf("A.a A.b B.b B.c B.AAA.a B.AAA.b \n");

  for(i=0;i<2;i++)
    printf("%d   %d   %d   %d   %d   %d \n",test_A[i].a,test_A[i].b,test_B[i].b,test_B[i].c,test_B[i].AAA.a,test_B[i].AAA.b);

  inin(&test_B->AAA);

  for(i=0;i<2;i++)
    printf("%d   %d   %d   %d   %d   %d \n",test_A[i].a,test_A[i].b,test_B[i].b,test_B[i].c,test_B[i].AAA.a,test_B[i].AAA.b);

  return 0;
}


Output:
1
2
3
4
5
A.a A.b B.b B.c B.AAA.a B.AAA.b 
2   3   101   102   103   104 
3   4   102   103   104   105 
2   3   101   102   1000   1001 
3   4   1001   1002   104   105 


Create a new paste based on this one


Comments: