title: How do i fill specific columns in a mutlidimensional array in C?
body: <p>I want to fill the 2nd and 4th columns with zeros. I have achieved this so far, but i can't figure out why. In main i tried to fill the whole array with zeros. In random1 i tried to fill specific cells with random numbers. I used the <code>for (j=0;j&lt;25;j=j+2)</code> in order to fill every second column with the random numbers, but still haven't achieved it. Can anyone help? Thanks in advance!</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  
  //int random1 (int );
  
  int random1 (int b[5][5])
  {
     int i,j;
     int *onedim = (int *)b; 
     srand(time(NULL));  
     for (j = 0; j &lt; 25; j = j + 2)
         onedim[j] = rand() % 19 - 9; 
     for (i = 0; i &lt; 5; i++)
     {
         for(j = 0; j &lt; 5; j++)
         {
             printf("%d\t", b[i][j]);
         }
         printf("\n");   
     }
     return 0;
  }
  
  int main (int argc, char **argv)
  {
      int i, j;
      int a[5][5];
      for(i = 0; i &lt; 5; i++)
          for(j = 0; j &lt; 5; j++)
          {
              a[i][j] = 0;
          }
      random1(a);
      return(EXIT_SUCCESS);
  }
  </code></pre>