title: How to "execute" Makefile in Ubuntu to run C program that reads from stdin and outputs to stdout/stderr
body: <p>I'm working on a homework problem that reads characters from an <strong>input.txt</strong> file and outputs the first word read into an <strong>output.txt</strong>, the second into an <strong>error.txt</strong>, then the third to <strong>output.txt</strong> again, and so on until it reaches the end of the <strong>input.txt</strong> file.  </p>
  
  <p><em>I should note this is all done using Ubuntu 18.04</em></p>
  
  <p>I was given a custom Makefile and had to edit a C program called <strong>split.c</strong> which would take the <strong>input.txt</strong> through the <strong>stdin</strong> and output to <strong>stdout/stderr</strong>. I can write my C program and have it listed below, however I can't test if it's correct because I do not understand how to run make, how to set up my files correctly and if my C program is correctly reading and outputing as it should.</p>
  
  <p>I have tried running the 'make' command in the terminal but I receive:</p>
  
  <p><em>make:  No targets specified and no makefile found.  Stop.</em></p>
  
  <p>I have looked at countless articles on Linux, making 'make files', etc. but I don't know what I'm being asked or what to do so I am at a stand still.  Guidance is greatly appreciated!</p>
  
  <p>The custom makefile looks like this and is called <strong>Makefile.dat</strong>:</p>
  
  <pre><code>CC=gcc
  CFLAGS=-Wall
  EXEC=split
  SRC=$(EXEC).c
  TEXT_DIR=test
  TEST_INPUT=$(TEST_DIR)/input.txt
  OUT=$(TEST_DIR)/stdout.txt
  ERR=$(TEST_DIR)/stderr.txt
  EXP_OUT=$(TEST_DIR)/output.txt
  EXP_ERR=$(TEST_DIR)/error.txt
  TEST_REQS=$(TEST_INPUT) $(EXP_OUT) $(EXP_ERR)
  DIFF=diff -bBqa
  
  all:  $(EXEC)
  
  $(EXEC): $(SRC)
     $(CC) $(CFLAGS) $(SRC) -o $(EXEC)
  
  .PHONY: test
  test: $(TEST_REQS) $(EXEC)
    ./$(EXEC) &lt; $(TEST_INPUT) &gt; $(OUT) 2&gt; $(ERR)
    $(DIFF) $(EXP_OUT) $(OUT)
    $(DIFF) $(EXP_ERR) $(ERR)
    echo TEST PASSED!
  
  .PHONY:  clean
  clean:
    $(RM) $(EXEC)
  </code></pre>
  
  <p>And my C program looks like this and is called <strong>split.c</strong>:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(){
     int input;
  
     // keep getting characters until end-of-file
     while((input = fgetc(stdin)) != EOF){
  
       // prints to stdout
       printf(stdout, "%d", input);
       if(input = " ")
         printf("\n");    // encounters whitespace so print new line
  
       // prints to stderr
       printf(stderr, "%d", input);
       if(input = " ")
         printf("\n");    // encounters whitespace so print new line
  
      }
  
      return 0;
  
   }
  </code></pre>
  
  <p>With the idea being that it takes the input file, then it'll print each letter into it's respective file, and if it encounters a space it'll print a new line before adding the next character into the other file.</p>
  
  <p>For example:</p>
  
  <p><strong>input.txt</strong> has the text:</p>
  
  <pre><code>"How do I do this stuff?"
  </code></pre>
  
  <p><strong>output.txt</strong> will have:</p>
  
  <pre><code> How
   I
   this
  </code></pre>
  
  <p><strong>error.txt</strong> will have:</p>
  
  <pre><code> do
   do
   stuff?
  </code></pre>
  
  <p>I fully expect that my C program is missing code.  My thinking when writing the program was, print to stdout, then if whitespace is encounterd, print a new line, then begin printing to stderr, and repeat until EOF is reached.</p>