title: How to read data from unknown input type (filestream or stdin) C
body: <p>I wanted to know how to read data from an unknown source of input, meaning I don't know if the user is going to just type a sentence or is he going to give me some text file.
  I've tried using <code>fscanf</code> since I've read it is meant for unformatted input type
  this is my code, Im suppose to get some type of input(file or just a sentence <code>(echo bla bla bla)</code> and <code>"int"</code> and print only the <code>"int"</code> first words. The program should be used for piping meaning the command would look like that :<br>
  There are 2 ways to ways of using the program:</p>
  
  <pre><code>1.echo "blabla" | myprog 2  (number of words to print)
  2.cat input.txt | myprog 2  (number of words to print)
  </code></pre>
  
  <p>The problematic line is line 16, I tried using <code>fscanf</code><br>
  Thanks!</p>
  
  <pre><code>  1 #include &lt;stdio.h&gt;
    2 #include &lt;ctype.h&gt;
    3 #include &lt;string.h&gt;
    4 #include &lt;stdlib.h&gt;
    5
    6
    7 int main(int argc, char *argv[]){
    8    char *words[32];
    9    int numofwords = atoi(argv[2]);
   10    int i=0;
   11    int len;
   12    char *word = malloc (32 * sizeof(char));
   13    char c;
   14   while (i&lt;=numofwords){
   15    if ((c = getc (argv[1])) != EOF){
   16         fscanf(argv[1],"%s",&amp;word);
   17         len = strlen (word);
   18         words[i] = malloc ((len+1) * sizeof(char));
   19         i++
   20    }
   21    printf(words[i]);
   22   }
   23   return 0;
   24 }
   25
  </code></pre>