I'm having some problems with spell-checker(pset 6). I'm trying to debugg with gdb, but when I try to run ./spell with gdb the following happens:
Reading symbols from /home/jharvard/Dropbox/C/Harvard/pset6/speller...done. "/home/cs50/pset6/dictionaries/large" is not a core dump: File format not recognized
I'm fairly confident that my pseudocode has no logic mistakes, but I'm not sure if I understood how to read words from the dictionary (I don't understand that const char* declaration), so I'll post that part of my code here:
/code snipped per honor code/
EDIT: My code is segfaulting when trying to load the words from the dictionary. I'm not sure I understood how fscanf works. What I think it does is: it takes one word at a time from a file* and put it where you tell it to put it. It also, returns 1 if one argument was read and NULL when the end of the file was reached. Taking that into account is that I wrote this, but it doesnt work:
// Initialize hash table
node* hashtable[26];
// Open dictionary file
FILE* file = fopen(dictionary, "r");
// For every word in file
while (true)
{
node* new_node = malloc(sizeof(node));
if (fscanf(file, "%s", new_node -> word) == 1)
{
// Hash word of new node
// Go to the linked list in that bucket
// Check if list is empty and insert new node there
// Check if new node belongs to the head of the linked list
// Try insert new node at the middle or tail
else
{
{
// Avoid duplicates
// Check for insertion at tail
// check for insertion in middle
// Check for insertion in middle
// Space hasn't been found yet. Update predptr
}
}
}
}
This is what outputs GDB.
Breakpoint 1, main (argc=2, argv=0xbffff084) at dictionary_test.c:34
warning: Source file is more recent than executable.
34 FILE* file = fopen(argv[1], "r");
(gdb) n
39 node* new_node = malloc(sizeof(node));
(gdb) n
40 if (fscanf(file, "%s", new_node -> word) == 1)
(gdb) n
Program received signal SIGSEGV, Segmentation fault.
__isoc99_fscanf (stream=0x0, format=0x80487e6 "%s") at isoc99_fscanf.c:30
30 _IO_acquire_lock_clear_flags2 (stream);
(gdb) n
Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.
(gdb) l
25 __isoc99_fscanf (FILE *stream, const char *format, ...)
26 {
27 va_list arg;
28 int done;
29
30 _IO_acquire_lock_clear_flags2 (stream);
31 stream->_flags2 |= _IO_FLAGS2_SCANF_STD;
32
33 va_start (arg, format);
34 done = _IO_vfscanf (stream, format, arg, NULL);
(gdb)
Thanks