title: Assigning values to a struct member without using the members name in c?
body: <p>I have a structure and what I would like to do is to assign values to its members using a for loop. That way I do not have to use the members name. Because the structure is long and i do not want 20 lines of <code>p_struct-&gt;member_name</code> etc. What I have so far is below, but i am not sure if i am going in the right direction.<br>
  In header file:  </p>
  
  <pre><code>typedef struct {
   int x;
   char ch;
    ...
    ...
  }data;
  data g_data;
  </code></pre>
  
  <p>in .c file...</p>
  
  <pre><code>data *p_data;
  p_data = &amp;(g_data.x)
  for(i=0 till struct_elements) {
      *p_data = (some value);
      p_data++; //next member
  }
  </code></pre>