title: How to print lines from stdin?
body: <p>I'm redirecting stdin to be output produced from the command ls -l when run on the command line, and I want to print out its results.</p>
  
  <p>So say after I run ls -l I get the following output:</p>
  
  <pre><code>total 519
  -rw-------  1 jeff  dev    1274 22 Jun 14:52 prinprog
  -rwx---xr--  1 jeff  dev   2410  6 Apr 12:10 temp.txt
  -rwxr----x  1 jeff  dev    8128  1 Feb  2013 yyz
  -rw-r--r--  1 jeff  dev      98 15 Feb  2013 yyz.c
  </code></pre>
  
  <p>Now after compiling my C program I do ls -l | ./testing and I have effectively changed the stdin from being the keyboard to what ever output was produced by the ls -l command. Now what I want to do in my C program is print out the output produced by the ls -l command.</p>
  
  <p>I do that by scanf() and a while loop. What I'm having trouble with is formatting my text. That first line "total 519" is kind of useless to me but its throwing me off.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main() {
  
  char permissions[10];
  int num;
  char user[20];
  char random[20];
  int fileSize;
  
  while(scanf("%s %d %s %s %d", permissions, &amp;num, user, random, &amp;fileSize) != EOF) {
      printf("%s %d %s %s %d\n", permissions, num, user, random, fileSize);
  }
  
  return 0;  
  } 
  </code></pre>