What is wrong with this C program : <p>I am trying to write a usb mass storage driver. I don't have a storage device, so I am trying to allocate some memory. below is the program I wrote to emulate
a 512*2048 (1 MB) size usb drive</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;


char ** called_func(char **mem, char start_sec, char num_of_sec)
{
    char **read_mem, row, column;
    read_mem = (char **)malloc(sizeof(char *) * 512 * num_of_sec);
    for(row = 0 ; row &lt; num_of_sec ; row++)
       for(column = 0 ; column &lt; 512 ; column++ )
            read_mem[row][column] = mem[row + start_sec][column];

    return read_mem;
}

int main()
{
    char **mem, row , column, i, j;
    char **ret;
    mem = (char **)malloc(sizeof(char *) * 512 * 2048);

    if(mem == NULL)
       printf("allocation failed\n");
    for(row = 0; row &lt; 2048 ; row++)
       for(column = 0 ; column &lt; 512 ; column++)
           mem[row][column] = 'a';


    ret = called_func(mem, 2, 6);//start sec, num of sectors this time I am going to read from the second sector, and total 6 sectors
    for(i=0;i&lt;2;i++)
    {
      for(j=0;j&lt;6;j++)
      {
        printf("ret[i][j] = %c",i, j, ret[i][j]);
      }
      printf("\n");
    }
    return 0;


}
</code></pre>

<p>I haven't wrote a C program in many months. Please tell where I am wrong as I keep getting segmentation fault.</p>
