title: fscanf() function error
body: <p>I'm a newbie to c programming. I've written a program using <code>fscanf()</code> function:</p>
  
  <pre><code>fscanf(fileptr, "%s\n", word);
  </code></pre>
  
  <p>But while I ran the program it was stuck in the terminal. I try to run <code>GDB</code> on the program and it show the following lines:</p>
  
  <pre><code>109     for (int i = 0; i &lt; 100; i++)
  (gdb) 
  111         fscanf(fileptr, "%s\n", word);
  (gdb) 
  __isoc99_fscanf (stream=0x603010, format=0x400cbd "%s\n") at isoc99_fscanf.c:26
  26  isoc99_fscanf.c: No such file or directory.
  </code></pre>
  
  <p>And then these lines:</p>
  
  <pre><code>(gdb) 
  _IO_vfscanf_internal (s=s@entry=0x603010, format=0x400cbd "%s\n", argptr=argptr@entry=0x7fffffffdd48, errp=errp@entry=0x0) at vfscanf.c:225
  225 vfscanf.c: No such file or directory.
  </code></pre>
  
  <p>Is there any problem with the compiler, Or am I missing something? I compiled with:</p>
  
  <pre><code>gcc -ggdb3 -O0 -std=c99 -Wall -Werror hash.c -o hash
  </code></pre>
  
  <p>Here is the full code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdbool.h&gt;
  #include &lt;ctype.h&gt;
  #include &lt;string.h&gt;  
  
  #define MAXLENGTH 10
  
  // structure for each node in hash
  typedef struct node
  {
      char* word;
      struct node* next;
  }
  node;
  
  // global pointer for the root node
  node* root = NULL;
  node* table[26] = {};
  
  // function declearations
  int hash_function(char data[MAXLENGTH]);
  void load_words(FILE* fileptr);
  bool check_word(char* word);
  
  // main function takes command line arguments
  int main(int argc, char** argv)
  {
      // validates user input at command line
      if (argc != 2)
      {
          printf("Invalid Input!\n");
          printf("Usage : ./hash &lt;word&gt;\n");
          return 1001;
      }
  
      // loads the dictionary
      FILE* file_ptr = fopen("dictionary.txt", "r");
      if (file_ptr == NULL)
      {
          printf("failed to load the file!\n");
          return 1002;
      }
      else
      {
          load_words(file_ptr);
      }
  
      // checks if the word is in dictionary
      if (check_word(argv[1]) == true)
      {
          printf("Word spelled right!\n");
          return 0;
      }
      else
      {
          printf("Word spelled wrong!\n");
          return 0;
      }
  }
  
  // hash function
  int hash_function(char data[MAXLENGTH])
  {
      if (isalpha(data[0]) != 0)
      {
          int res = tolower(data[0]);
          res = res - 'a';
          return res;
      }
      else
      {
          printf("not a word!\n");
          return -1;
      }
  }
  
  // check_word function
  bool check_word(char* word)
  {
      int hash = hash_function(word);
      if (hash != -1)
      {
          root = table[hash];
  
          while(root != NULL)
          {
              if (strcmp(word, root-&gt;word) == 0)
              {
                  return true;
              }
          }
      }
      return false;
  }
  
  // load words into hash table
  void load_words(FILE* fileptr)
  {
      char word[10];
  
      for (int i = 0; i &lt; 100; i++)
      {
          fscanf(fileptr, "%s\n", word);
  
          int hash = hash_function(word);
  
          if (hash != -1)
          {
              if (table[hash] == NULL)
              {
                  table[hash] = malloc(sizeof(node));
                  if (table[hash] == NULL)
                  {
                      printf("memory allocation failed!\n");
                      return;
                  }
  
                  table[hash]-&gt;word = word;
                  table[hash]-&gt;next = NULL;
              }
              else
              {
                  root = table[hash];
  
                  while (root-&gt;next != NULL)
                      root = root-&gt;next;
  
                  node* newNode = malloc(sizeof(node));
                  if (newNode == NULL)
                  {
                      printf("memory allocation failed!\n");
                      return;
                  }
  
                  newNode-&gt;word = word;
                  newNode-&gt;next = NULL;
  
                  root-&gt;next = newNode;
              }       
          }
          else
          {
              printf("hash failed!\n");
          }
      }
  }
  </code></pre>
  
  <p>I'm using Ubuntu 14.04 and I've install build-essential. Any advice would be very much appreciated.</p>
  
  <p>Thanks in advance.</p>