Hello all, recently I've been working on a HashTable data structure and have attempted to make it work for a project. Currently, I am encountering an infinite loop when I make it about two lines deep into the input file I need to parse through. From what I can surmise, my functions for key creation and inserting into the hash table are not the issue, but it may be how I'm parsing through the lines of my input file. I cannot see the fault in my logic that's causing the issue but I hope you may be able to help me. I'm currently just trying to get past reading and inserting the names from the input file so some of the comments in main are irrelevant, I will also attach the files to this post in zip file. Here is my code for main.
Code:
#include "HashTable.h"
#include <string.h>
#define MAX_LINE_LENGTH 100
int main()
{
//create hash table size 100
//open file nbaTeamNames.csv
//read in each team name by line and use put to write an element for
//the team with intial wins and loss of 0
//open file nbaData2019
//read by line and determine a winner and loser
//use get function to obtain element associated with team and increment
//wins and losses accordingly
//after all lines read, reopen nbaTeamNames.csv
//print out team name and win loss count per line
//use get function to get win loss count
//Print result should look like
//"San Antonio Spurs: XX Wins - XX Losses"
HashTable Hash = newHashTable(100);
Element tempElm;
Element *e;
FILE *inputFile;
inputFile = fopen("nbaTeamNames.csv", "r");
if(inputFile == NULL){
perror("Error opening file");
return -1;
}
char nextLine[MAX_LINE_LENGTH];
char currLine[MAX_LINE_LENGTH];
while(fgets(nextLine, MAX_LINE_LENGTH, inputFile)!= NULL){
int deli = strlen(nextLine) - 1;
if(nextLine[deli] == '\n'){
nextLine[deli-1] = '\0';
}
sscanf(nextLine, "%[^\n]\n", currLine);
strcpy(tempElm.szTeamName, currLine);
tempElm.losses = 0;
tempElm.wins = 0;
put(Hash, tempElm);
printf("%s\n", tempElm.szTeamName);
}
fclose(inputFile);
return 0;
}