title: Reading variable number of structs from shared memory
body: <p>In a C program , i create a shared memory segment of large size and then put a variable number of structs into it (2 in this example).</p>
  
  <pre><code>strcut message * x;
  x = (struct message *)shmat(shmid,NULL,0);
  x[0].a = 1;
  x[0].b = 2;
  x[1].a = 3;
  x[1].b = 4;
  </code></pre>
  
  <p>There is a reader program which has to read all the structs written in the shared memory segment but does not know how many structs are there.
  I have tried the following way:</p>
  
  <pre><code>struct message * x;
  x = (struct message *)shmat(shmid,NULL,0);
   while(x!=NULL)
   {
  printf("x.a = %d\n",x-&gt;a);
  printf("x.b = %d\n",x-&gt;b);
  printf("\n\n");
  x=x++;
  }
  </code></pre>
  
  <p>It gives me the 2  structs correctly but after that it gives me 0 (or random garbage values ) for many more times ( for both a and b )   until it runs out of the shared memory segment and then gives a segmentation fault.
  How do i go about it?</p>
  
  <p>I am using UBUNTU.</p>