title: Unable to initialize an array of structs
body: <p>I'm trying to initialize array cells of type struct using memset.
  The program successfully compiles, however Valgrind is not happy with something related to memseting those cells. 
  The commented-out code doesn't work either.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;assert.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;string.h&gt;
  
  #define MAX_DATA 512
  #define MAX_ROWS 100
  
  
  
  struct Address {
          int id;
          int set;
          char name[MAX_DATA];
          char email[MAX_DATA];
  };
  
  struct Database{
          struct Address rows[MAX_ROWS];
  };
  
  struct Connection{
          FILE* file;
          struct Database* db;
  };
  
  
  void die(const char* message)
  {
          if(errno){
                  perror(message);
          }else{
                  printf("ERROR: %s\n", message);
          }
          exit(1);
  }
  
  
  
  void Database_load(struct Connection* conn)
  {
          int rc = fread(conn-&gt;db, sizeof(struct Database), 1, conn-&gt;file);
          if (rc != 1)
          {
                  die("Failed to load database.");
          }
  }
  
  
  struct Connection* Database_open(const char* filename, char mode)
   {
          struct Connection* conn = malloc(sizeof(struct Connection));
          if (!conn)
          {
                  die("Memory error");
          }
  
          if (mode == 'c')
          {
                  conn-&gt;file = fopen(filename, "w");
          }
          else
          {
                  conn-&gt;file = fopen(filename, "r+");
  
                  if(conn-&gt;file) {
                          Database_load(conn);
                  }
          }
  
          if(!conn-&gt;file) die("Failed to open file");
          return conn;
  }
  
  
  void Database_create(struct Connection* conn)
  {
          int i = 0;
  
          for(i = 0; i &lt; MAX_ROWS; i++) {
                  //struct Address addr = {.id = i, .set = 0};
                  //conn-&gt;db-&gt;rows[i] = addr;
                  memset(&amp;(conn-&gt;db-&gt;rows[i]), 0, sizeof(struct Address));
                  conn-&gt;db-&gt;rows[i].id = i;
          }
  }
  
  
  
  
  int main(int argc, char* argv[])
  {
          if(argc &lt; 3) die("USAGE: ex17 &lt;dbfile&gt; &lt;action&gt; [action params]");
  
          char* filename = argv[1];
          char action = argv[2][0];
          struct Connection* conn = Database_open(filename, action);
          int id = 0;
          if(argc &gt; 3) id = atoi(argv[3]);
          if(id &gt;= MAX_ROWS) die("There's not that many records.");
  
  
          Database_create(conn);
  
          return 0;
  }                        
  </code></pre>
  
  <p>related Valgrind error -</p>
  
  <pre><code>==16227== Conditional jump or move depends on uninitialised value(s)
  ==16227==    at 0x4C3009C: memset (vg_replace_strmem.c:1224)
  ==16227==    by 0x400BA8: Database_create (ex17.c:108)
  ==16227==    by 0x400EE1: main (ex17.c:174)
  </code></pre>