title: SDL - Update Surface in C
body: <p>i use SDL Lib and SDL_TTF Lib</p>
  <p>I have a code that allows you to enter text
  And then display the text on my window
  so here the code</p>
  <pre class="lang-c prettyprint-override"><code>    TTF_Init();
      SDL_Init(SDL_INIT_VIDEO);
      TTF_Font * font = TTF_OpenFont(&quot;C:\\Windows\\Fonts\\Arial.ttf&quot;, 25);
      SDL_Color color = { 255, 255, 255 };
      SDL_Surface * surface = TTF_RenderText_Solid(font,&quot;&quot;, color);
  
      
      SDL_Window * window = SDL_CreateWindow(&quot;SDL_ttf in SDL2&quot;,
          SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640,
          480, 0);
      SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, 0);
  
  
      SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface);
      int texW = 200;
      int texH = 200;
      SDL_QueryTexture(texture, NULL, NULL, &amp;texW, &amp;texH);
      SDL_Rect dstrect = { 200, 200, texW, texH };
      SDL_RenderCopy(renderer, texture, NULL, &amp;dstrect);
          
      SDL_RenderPresent(renderer);
      while (program_launched)
      {
          SDL_bool has_type = SDL_FALSE;
          SDL_WaitEvent(&amp;event);
          if(event.type == SDL_QUIT)
              program_launched = SDL_FALSE;
          else if( event.type == SDL_KEYDOWN)
          {
              if(event.key.keysym.sym == SDLK_BACKSPACE &amp;&amp; len)
              {
                  rep[len - 1] = 0;
                  len--;
                  has_type = SDL_TRUE;
              }
             
              if(event.key.keysym.sym == SDLK_v &amp;&amp; (SDL_GetModState() &amp; KMOD_CTRL) &amp;&amp; SDL_HasClipboardText())
              {
                  char *tmp = SDL_GetClipboardText();
                  size_t l = strlen(tmp);
                  size_t l_copy = len + l &lt; LEN_MAX ? l : LEN_MAX - len;
                  strncpy(rep + len, tmp, l_copy);
                  len += l_copy;
                  SDL_free(tmp);
                  has_type = SDL_TRUE;
              }
              if(event.key.keysym.sym == SDLK_c &amp;&amp; (SDL_GetModState() &amp; KMOD_CTRL))
                  SDL_SetClipboardText(rep);
          }
          else if(event.type == SDL_TEXTINPUT)
          {
              size_t l = strlen(event.text.text);
              size_t l_copy = len + l &lt; LEN_MAX ? l : LEN_MAX - len;
              strncpy(rep + len, event.text.text, l_copy);
              len += l_copy;
              has_type = SDL_TRUE;
          }
          if(has_type)
  
              surface = TTF_RenderText_Solid(font,rep, color);
              texture = SDL_CreateTextureFromSurface(renderer, surface);
              SDL_QueryTexture(texture, NULL, NULL, &amp;texW, &amp;texH);
              SDL_Rect dstrect = { 0, 0, texW, texH };
              SDL_RenderCopy(renderer, texture, NULL, &amp;dstrect);
              SDL_RenderPresent(renderer); 
      
      }
  </code></pre>
  <p>It's to (has-type) that I display the buff (rep)</p>
  <p>But my problem is here:
  <a href="https://i.stack.imgur.com/DM6rd.png" rel="nofollow noreferrer">I can write and display in the window a text</a></p>
  <p>But if i do a backspace and i write
  <a href="https://i.stack.imgur.com/2qoDQ.png" rel="nofollow noreferrer">The texts overlap because the window, at least the rectangle is not updated</a></p>
  <p>Is it possible to delete the content of my window (to display the buff without overlapping) ?</p>
  <p>I use this documentation
  <a href="https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.pdf" rel="nofollow noreferrer">https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.pdf</a>
  I had tried with this function: SDL_UpdateWindowSurface(window);
  But nothing helps</p>
  <hr />
  <p>Compiler: GCC</p>
  <p>OS: Windows</p>