I have a while loop that reads through a CSV file, gets the first and second entries, and adds it into a hash table implemented in C. I've tested it with small files with around 40 entries, and it works fine, but when I try to pass in any file larger than that, the WHILE part causes an infinite loop.
The code that handles the adding is shown below:
void populateTable(Table *table, char *name) {
FILE *file = fopen(name, "r");
if(file != NULL) {
while(!feof(file)) {
char line[128];
fgets(line, sizeof line, file);
char key[64];
int value;
sscanf(line, "%[^','],%d", key, &value);
addEntry(table, key, value);
}
}
fclose(file);
return;
}
I've tried using GDB to debug the program. When I have 42 entries, all entries are entered correctly, and they can be printed and accessed correctly. When there are any more, the code becomes unresponsive. When I step through with GDB, it says
#0 __lll_lock_wait_private() at ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:97
#1 0x00007ffff763f518 in _L_lock_28 () from /lib/x96_64-linux-gnu/libc.so.6
#2 0x00007ffff763f4b1 in _IO_feof (fp=0x60c070) at feof.c:37
#3 0x0000000000402e78 in populateTable (table=0x604250, name=0x40310b "data/census.csv") at Table.c:193
#4 0x00000000004016aa in main (argc=2, argv=0x7fffffffeae8) at server.c:189