title: SDL event handling not working
body: <p>I'm currently learning SDL by reading Lazy foo tutorials. I'm using code blocks 13.12 on Linux. I'm unable to get event handling to work correctly.</p>
  
  <p>I'm basically trying to display an image (which works great), but no matter how many times I click on the close button, it won't close</p>
  
  <p>Code:</p>
  
  <pre><code>#include &lt;SDL2/SDL.h&gt;
  #include &lt;stdio.h&gt;
  //Declaring the main window, the main surface and the image surface
  SDL_Window *window = NULL;
  SDL_Surface *scrsurface = NULL;
  SDL_Surface *imgSurface = NULL;
  SDL_Event event;
  int run = 1;
  
  //The function where SDL will be initialized
  int init();
  //The function where the image will be loaded into memory
  int loadImage();
  //The function that will properly clean up and close SDL and the variables
  int close();
  
  //The main function
  int main(void){
      if(init() == -1)
          printf("Init failed!!!");
      else{
          if(loadImage() == -1)
              printf("loadImage failed!!!");
          else{
  
              //Displaying the image
  
              while(run){
                  //Event handling
                 while(SDL_PollEvent(&amp;event)){
                      switch(event.type){
                          case SDL_QUIT:
                              run = 0;
                              fprintf(stderr, "Run set to 0");
                              break;
                          default:
                              fprintf(stderr, "Unhandled event");
                           break;
                      }
                  } 
                  //Blitting nad updating
                  SDL_BlitSurface(imgSurface, NULL, scrsurface, NULL);
                  SDL_UpdateWindowSurface(window);
              }
          close();
  
          }
      }
      return 0;
  
  }
  
  int init(){
   if(SDL_Init(SDL_INIT_VIDEO) &lt; 0)
      return -1;
   else{
      window = SDL_CreateWindow("SDL_WINDOW", SDL_WINDOWPOS_UNDEFINED,  SDL_WINDOWPOS_UNDEFINED, 900, 900, SDL_WINDOW_SHOWN);
      if(window == NULL)
          return -1;
      scrsurface = SDL_GetWindowSurface(window);
  
  }
  return 0;
  }
  
  
  int loadImage(){
      imgSurface = SDL_LoadBMP("Test.bmp");
      if(imgSurface == NULL)
          return -1;
      else{
  
      }
      return 0;
  }
  
  int close(){
      SDL_FreeSurface(imgSurface);
      SDL_DestroyWindow(window);
      window = NULL;
      SDL_Quit();
      return 0;
  
  }
  </code></pre>
  
  <p>`</p>