title: Invalid Initializer in C
body: <p>I'm a beginner in the C Programming language and I wanted to write a hashing program. I can write this program with a specified number of <code>typedef ... Name</code> elemenst (in an array) but, when I use dynamic allocation, an &quot;invalid initializer&quot; error appears.</p>
  <pre class="lang-c prettyprint-override"><code>    typedef char Name[30];
      
      Name hashTable[MAX];
      
      int hash(Name name){
        int long sum = 0;
        int len=strlen(name);
        int i = 0;
        for (; i&lt;len;i++)
          sum += name[i];
        sum = sum % MAX;
        printf(&quot;\nhash of [%s] = %ld\n&quot;,name,sum);
        return sum;
      }
  
      void main(){
        int i,j;
        for(i=0;i&lt;MAX;i++)
          strcpy(hashTable[i],&quot;&quot;);
        int pos, x, cont=1;
        printf(&quot;number of names: &quot;);
        scanf(&quot;%d&quot;,&amp;x);
        while (x&gt;=cont){
         Name name = malloc(sizeof(Name));  // why this line have the error of &quot;invalid initializer&quot;?
         printf(&quot;\ntype the %dº name: &quot;,cont);
         scanf(&quot;%s&quot;,name);
         pos=hash(name);
         strcpy(hashTable[pos],name);
         cont++;
      }
  </code></pre>