title: How to use scanf to read each line of a file with space?
body: <p>So I'm trying to write a c program that can read each line of a file pass to it by command line and print out each line. My code look like this:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(void){
  
          char num[20];
          for (;;){
                  if((scanf("%[^\n]s", num)) != 1){
                          break;
                  }
                  printf("%s\n", num);
          }
  }
  </code></pre>
  
  <p>The unix command line is: ./printeachline &lt; num.txt</p>
  
  <p>the num.txt includes these lines:</p>
  
  <pre>
  01 0111111119
  111122222228
  123400000000
  1234kk444k44
  oooo11111111
  o dk39754i2oo
  002711111116
  124145245 246623
  0027111111167
  888888888888
  100900000011
  </pre>
  
  <p>What I'm expecting to print out is every line in num.txt, However when I enter the command only the first line is printed, that is 01 0111111119. How could I fix this????</p>