title: Moving a square in SDL2 using C
body: <p>I'm unable to move the rectangle I made in the program. There is no error message in the compiler when I run the program. Can you please tell me what I missed out in the keyboard event. Other event that I assigned to the window works fine. Thanks (an example will also be helpful).</p>
  
  <pre><code>#include &lt;SDL.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main()
  {
      SDL_Window *o;
      SDL_Renderer *r;
      SDL_Event e;
      int i = 1;
  
      SDL_Rect q;
  
      SDL_Init(SDL_INIT_VIDEO);
  
      o = SDL_CreateWindow("Game test",
                              SDL_WINDOWPOS_UNDEFINED,
                              SDL_WINDOWPOS_UNDEFINED,
                              1024,
                              800,
                              SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
  
      r = SDL_CreateRenderer(o, -1,SDL_RENDERER_ACCELERATED);
      SDL_SetRenderDrawColor(r,0,0,255,255);
      SDL_RenderClear(r);
      //Creating a box
      q.x=475;
      q.y=700;
      q.h=50;
      q.w=50;
      SDL_SetRenderDrawColor(r,0,0,0,255);
      SDL_RenderFillRect(r,&amp;q);
      //SDL_Delay(10);
  
      SDL_RenderPresent(r);
  
      while(i)
      {
          while(SDL_PollEvent(&amp;e) !=0)
          {
              if(e.type == SDL_QUIT)
                  i=0;
              else if(e.type == SDL_KEYDOWN)
              {
                  switch(e.key.keysym.sym)
                  {
                  case SDLK_ESCAPE:
                  case SDLK_q:
                      i=0;
                  break;
                  case SDLK_UP:
                      q.y -=10;
                      SDL_Delay(11);
                  break;
                  case SDLK_DOWN:
                      q.y +=10;
                      SDL_Delay(11);
                  break;
                  case SDLK_RIGHT:
                      q.x +=10;
                      SDL_Delay(11);
                  break;
                  case SDLK_LEFT:
                      q.x -=10;
                      SDL_Delay(11);
                  break;
                  default:
                  break;
                  }
              }
          }
      }
  
  
      SDL_DestroyWindow(o);
      SDL_DestroyRenderer(r);
      SDL_Quit();
  
      return 0;
  }
  </code></pre>