title: How to compare a string with EOF?
body: <p>I've created a program that acts like a unix-shell. Namely if type something like "./helloWorld" it will execute the program and then wait for additional input. If the input is EOF (Ctrl + D) then the program must terminate.</p>
  
  <p>What I'm struggling with is trying to compare the input without using getchar() or any method that requires additional input.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include&lt;unistd.h&gt; /* for fork() */
  #include&lt;sys/types.h&gt; /* for pid_t */
  #include&lt;sys/wait.h&gt; /* fpr wait() */
  
  int main(int argc, char* argv[])
  {   
      pid_t pid,waitPid;
      int status;
      char fileName[256];
      while(!feof(stdin))
      {
      printf(" %s &gt; ", argv[0]);
      if (fgets(fileName, sizeof(fileName), stdin) != 0)
      {
          fileName[strcspn(fileName, "\n")] = '\0'; //strcspn = calculates the length of the initial fileName segment, which  consists of chars not in str2("\n")
  
      char *args[129];
      char **argv = args;
      char *cmd = fileName;
      const char *whisp = " \t\f\r\b\n";
      char *token;
      while ((token = strtok(cmd,whisp)) != 0) // strtok = breaks string into a series of tokens using the delimeter delim(whisp)
      {
          *argv++ = token;
          cmd = 0;
      }// /while
  
      if (getchar() == EOF)
      {
      break;
      }
  
      *argv = 0;
  
      pid = fork();
      if (pid == 0){
      execv(args[0], args);
      fprintf(stderr, "Oops! \n");
      } // /if
      waitPid = wait(&amp;status);
  
  
  
  }// /if(fgets..)
  } // /while
  return 1;
  </code></pre>
  
  <p>}</p>
  
  <p>I want to replace the  </p>
  
  <pre><code>if (getchar() == EOF)
          {
          break;
          }
  </code></pre>
  
  <p>with a direct comparison. Like so: if (fileName == EOF) { break; }</p>
  
  <p>Is this even possible? I've tried casting and other methods,but nothing has worked so far. Is there a different method that I haven't thought of?
  To be more clear, I want to know if my thought is doable and if it is how to implement it. If not how can I terminate my program with CTRL + D and without additional input.</p>