Segfault when passing structure from main() to worker functions
<p>I am trying to write a simple game in C and I'm getting a SEGFAULT and have no idea why!</p>

<p>Here is the code for the program:</p>

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

#define MAX_PLYS_PER_GAME (1024)
#define MAX_LEN (100)

typedef struct {
   char positionHistory[MAX_PLYS_PER_GAME][MAX_LEN];
} Game;

void getInitialGame(Game * game) {
    memset(game-&gt;positionHistory, 0, MAX_PLYS_PER_GAME*MAX_LEN*sizeof(char));
}

void printGame(Game game) {
    printf("Game -&gt; %p (%d)\n", &amp;game, sizeof(game));
    fflush(stdout);
}

int hasGameEnded(Game game) {
    printGame(game);
    return 0;
}

int main(int argc, char *argv[]) {
    Game game;
    getInitialGame(&amp;game);

    if (hasGameEnded(game))
        return -1;

    return 0;
}
</code></pre>

<p>I tried debugging with gdb but the results didn't get me too far:</p>

<pre><code>C:\Users\test&gt;gdb test.exe
GNU gdb 5.1.1 (mingw experimental)
&lt;snip&gt;
This GDB was configured as "mingw32"...
(gdb) run
Starting program: C:\Users\test/test.exe

Program received signal SIGSEGV, Segmentation fault.
0x00401368 in main (argc=1, argv=0x341c88) at fast-chess-bug.c:29
29              if (hasGameEnded(game))
(gdb) bt
#0  0x00401368 in main (argc=1, argv=0x341c88) at fast-chess-bug.c:29
</code></pre>