SDL2 window opens for a few seconds and closes

My SDL2 window opens and closes immediately. But the code still runs.

Here’s a link to the Github page with my code: https://github.com/chrismp/tic-tac-toe
And here’s the git repo itself if you want to clone it https://github.com/chrismp/tic-tac-toe.git

Why does the window close, but the code still runs in the while loop?

I simplified my code and posted my question on StackOverflow: http://stackoverflow.com/questions/35530426/why-does-my-sdl2-window-open-for-a-second-then-immediately-closes