title: C: How to shmat a struct?
body: <p>I have a struct that looks like this:</p>
  
  <pre><code>struct data {
    int code;
    char name[25], fnum[8];
  };
  </code></pre>
  
  <p>Then I try to use it as a shared memory like this:</p>
  
  <pre><code>int dataSID = shmget(100002, sizeof(struct data), IPC_CREAT | 0666);
  </code></pre>
  
  <p>and attach it like this:</p>
  
  <pre><code>struct data *com = shmat(dataSID, 0, 0);
  </code></pre>
  
  <p>And finally I try filling the values likes this:</p>
  
  <pre><code>(*com).code = 1;
  scanf("%s", (*com).name);
  </code></pre>
  
  <p>And I get segmentation fault on the <code>scanf</code>.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Does <code>shmat</code> properly allocate memory for the struct?</p>