title: C Printf in while and if loop print twice
body: <p>I'm making a C program that display active foreground window but i have got a problem as mentionned in the topic, it prints twice all string beside (%s, new_window). I've read many topic about this printf problem but none of them does work for me. Here is my code</p>
  
  <pre><code>int main() {
      char window[256]= "hello";
      char new_window[256] = "hello";
      HWND handle = GetForegroundWindow();
      GetWindowText(handle, window, 256);
      //different
      while(1){
          HWND handle = GetForegroundWindow();
          GetWindowText(handle, window, 256);
          if(strcmp(window, new_window)) {
              strcpy(new_window,window);
              if (strcmp(window, new_window)){
                   printf("%s Active: \n", new_window);
                   fflush(stdout);
  
              }
              else {
               printf("%s Active: \n", window);
               fflush(stdout);
              }
          }
      }
  }
  </code></pre>
  
  <p>Output example when i switch windows (here netbeans and firefox):</p>
  
  <blockquote>
  <pre><code>    CLab - NetBeans IDE 8.2 Active: 
       Active: 
      ZeroDay - Mozilla Firefox Active: 
       Active: 
      CLab - NetBeans IDE 8.2 Active: 
       Active: 
      ZeroDay - Mozilla Firefox Active: 
       Active: 
      CLab - NetBeans IDE 8.2 Active:
  </code></pre>
  </blockquote>
  
  <p>Output i want:</p>
  
  <blockquote>
  <pre><code>    CLab - NetBeans IDE 8.2 Active: 
  
      ZeroDay - Mozilla Firefox Active: 
  
      CLab - NetBeans IDE 8.2 Active: 
  
      ZeroDay - Mozilla Firefox Active: 
  
      CLab - NetBeans IDE 8.2 Active:
  </code></pre>
  </blockquote>