title: Read word from file into simple linked list
body: <p>I need to write a program to read from a file, then save the words into a linked list for further use. I decided to read the text character by character using fgetc, then save all into the list each time a newline (<code>'\n'</code>) or space (<code>' '</code>) is detected, indicating one word. 
  Sorry I'm a newbie in file pointers, this is what I've gotten so far: </p>
  
  <pre><code>struct list { //global
  char string[30];
  struct list *next;
  };
  
  
  int main(void) {
  
      FILE *filePtr;
      char file[] = "text.txt";
      char tempStr[30];
      list *curr, *header;
      char c;
      int i = 0;
      curr = NULL;
      header = NULL;
  
      if((filePtr = fopen(file, "r")) == NULL) {
          printf("\nError opening file!");
          getchar();
          exit(101);
      }
      printf("\nFile is opened for reading.\n");
  
      while(!EOF) {
          while((c = fgetc(filePtr) != ' ') &amp;&amp; (c = fgetc(filePtr) != '\n')) {
              curr = (list*)malloc(sizeof(list));
              //c = fgetc(filePtr);
              tempStr[i] = fgetc(filePtr);
              i++;
              }
  
          tempStr[i] = '\0';
  
          strcpy(curr-&gt;string, tempStr);
          curr-&gt;next = header;
          header = curr;
  
          i = 0;
      }
  
      while(curr!=NULL) {
          printf("%s - ", curr-&gt;string); //This will not print.
          curr = curr-&gt;next;
      }
  
      if(fclose(filePtr) ==  EOF) {
          printf("\nError closing file!");
          getchar();
          exit(102);
      }
      printf("\nFile is closed.\n");
  
      getchar();
      getchar();
  
  }
  </code></pre>
  
  <p>If the text file: </p>
  
  <pre><code>have a nice day
  </code></pre>
  
  <p>Desired output: </p>
  
  <pre><code>have - a - nice - day
  </code></pre>
  
  <p>But, I could not print out anything except the file opened and closed.</p>
  
  <p>Thanks.</p>