title: Using strtok only works if I put the delimiter after the last item
body: <p>So I am trying to open and read files based on stdinput. I've used strtok to parse the input so that the user can input multiple files. I've set the delimiter to space.</p>
  
  <pre><code>int main(const int argc, const char *argv[]){
      if (argc == 1) {
          char str[100];
          const char delim[2] = " ";
          printf("Enter a filename:\n");
  
          fgets(str, 100, stdin);
          char *ptr = strtok(str, delim);
          while (ptr != NULL){
              FILE *fp = fopen(ptr, "r");
              if ((fp == NULL)) {
                  fprintf(stderr, "failed to open %s\n", ptr);
              }
              else{
                  printf("Opening file: %s\n", ptr);
                  char c;
                  while ((c = fgetc(fp)) != EOF){
  
                      if (c != ' '){
                          putchar(c);
                      }
                      if (c == ' ') {
                          printf("\n");
                      }
  
                  }
                  fclose(fp);
              }
              ptr = strtok(NULL, delim);
          }
          return 0;
      }
  </code></pre>
  
  <p>If I input "example.txt example2.txt", it will read example.txt, and then say failed to open example2.txt. However, if I input "example.txt example2.txt " (notice the extra space), it will read both of them correctly, but it will say "failed to open" with no file name at the end. Also, reading one file by itself results in "failed to open". Any ideas?</p>