title: Exiting a program when user enters Ctrl+d in C
body: <p>I am currently working on an assignment for class in which we have to write a program that takes user input from the command line.</p>
  
  <p>The program should continue to take input from the user until a Ctrl+d character is written on its own line.</p>
  
  <p>For example:</p>
  
  <p>%./test</p>
  
  <ul>
  <li>this is some text</li>
  <li>this is a new line</li>
  <li>ctrl+d</li>
  </ul>
  
  <p>The program would stop after the last line (the '-' characters are just to show the user that they are still entering text).</p>
  
  <p>So far I have this:</p>
  
  <pre><code>char c;
  
  printf("- ");
  
  while (c != EOF) {
      scanf(" %c", &amp;c);
      printf("- ");
  }
  </code></pre>
  
  <p>But when i type ctrl+d on execution it doesn't exit, any help would be much appreciated.</p>
  
  <p>Also I would like this to work on my mac, so if anyone could shed light on if there is a different way to do this there (as cmd+d just splits the terminal window), that would also be much appreciated.</p>
  
  <p>Thanks in advance!</p>