title: How to pause between functions in a program in C with GCC?
body: <p>So my problem is my program runs too fast that I can't see how it behaves. It's supposed to make the text crawl along the edges of the terminal. I tried to use <code>sleep()</code> to make a short pause between<code>printf(...)</code>s so that it I can see where the text us going while it prints.</p>
  
  <p>This is what it looks like: </p>
  
  <p><a href="http://i.imgur.com/B6FFbNp.gif" rel="nofollow">http://i.imgur.com/B6FFbNp.gif</a></p>
  
  <p>So I put <code>sleep()</code> function after the <code>printf</code>s so that it will pause before starting the loop again and make the text move slowly. But what happens is it pauses the programs indefinitely before it even starts. This also happens with <code>usleep</code> and <code>system("pause 1")</code>. This is what it looks like:</p>
  
  <p><a href="http://i.imgur.com/krGW3lB.gif" rel="nofollow">http://i.imgur.com/krGW3lB.gif</a></p>
  
  <p>==================================================================================</p>
  
  <p>EDIT:</p>
  
  <p>Okay, I figured it out on my own. It seems that <code>sleep()</code> only works if I put <code>\n</code> in my strings. I don't know why. I didn't even read this in the damn manuals.</p>
  
  <p>So if you have</p>
  
  <pre><code>printf("HELLO\n");
  sleep(3);
  printf("HELLO\n");
  sleep(3);
  printf("HELLO\n");
  </code></pre>
  
  <p>It will result in:</p>
  
  <p><code>HELLO</code> </p>
  
  <p>[pause for 3 seconds]</p>
  
  <p><code>HELLO</code> </p>
  
  <p>[pause for 3 seconds]</p>
  
  <p><code>HELLO</code></p>
  
  <p>but if you remove the newline characters it will:</p>
  
  <p>[pause for 9 seconds]
  <code>HELLO HELLO HELLO</code></p>
  
  <p>I don't know why this happens but it just does</p>
  
  <p>==================================================================================
  EDIT: </p>
  
  <p>This is how I wanted my program to work:
  <a href="http://i.imgur.com/DXv7E60.gif" rel="nofollow">http://i.imgur.com/DXv7E60.gif</a></p>
  
  <p>Thank you for your answers</p>