title: Reading a text file into a hashTable
body: <p>I have a hashTable and I have been trying to Read key/data pairs into it from a text file. When i read it in it appears to have been read in correctly but when i print the contents only the last entry in the textfile is being printed at every index of the table. Here is my readFile, saveFile functions: </p>
  
  <pre><code>int readFile(char * fileName, HTable * hashTable){
  char *key = malloc(sizeof(char*));
  char *data = malloc(sizeof(char*));
  int eof;
  //char buf[50];
  
  //Create file pointer and point it at fild to open
  FILE * fp;
  fp = fopen(fileName, "rb+");
  
  //check if file exists
  if(!fp){
      printf("File could not be opened\n");
      return 0;
  }
  
  //Set a temp Node to hold data, read data into the temp Node
  //and insert temp into hashtable
  printf("Here we go\n");
  
  while(1){
      eof = fscanf(fp, "%s %s", key, data);
      if(EOF == eof)
          break;
  
      //fgets(buf, 50, fp);                                   
      //sscanf(buf, "%s %s", key, data);
      insertData(hashTable, key, data);
      printf("Index %d: %s %s\n\n", hashTable-&gt;hashFunction(hashTable- 
              &gt;size, key), key, data);
  
  }
  
  //Close file pointer
  fclose(fp);
  
  return 1;
  }
  
  void saveFile(char * fileName, HTable * hashTable){
  //Create a FILE pointer and point it to the file to open or create
  FILE * fp;
  fp = fopen(fileName, "wb+");
  
  //If the file does not exist or cannot be created give error message
  if(!fp){
      printf("ERROR: File could not be created\n");
      return;
  }
  
  
  //for each index of the hashTable write its contents to the file
  for(int i = 0; i &lt; hashTable-&gt;size; i++){
      Node * temp = hashTable-&gt;table[i];
      while(temp != NULL){
          fprintf(fp, "%s %s \n", temp-&gt;key, temp-&gt;data);
          temp = temp-&gt;next;
          printf("saved....\n");
      }
      printf("Index %d saved\n", i);
  }
  
  //Close file pointer
  fclose(fp);
  
  }
  </code></pre>
  
  <p>And my output when i try to read the file:</p>
  
  <p>// This is the output from the readFile telling me where the data has gone</p>
  
  <p>Index: 1
  Index 1: Facebook sjfl253sFace</p>
  
  <p>Index: 2
  Index 2: Gmail 343728Gamil</p>
  
  <p>Index: 3
  Index 3: Insta alsdhfishInsta</p>
  
  <p>// This is the output from my main
  Index 1: Insta alsdhfishInsta
  Index 2: Insta alsdhfishInsta
  Index 3: Insta alsdhfishInsta</p>
  
  <p>// This is the end of main when i delete the hashTable
  // It stops at 2 and gives me a malloc error
  Completed deletion of index 1 of 5
  Completed deletion of index 2 of 5</p>