Skip to main content
updated code with new check function node initialization and valgrind output.
Source Link
Jake
  • 37
  • 5

Valgrind output for lalaland.txt

dictionary.c:57:17: runtime error: member access within null pointer of type 'node' (aka 'struct node')
==19852== 
==19852== Process terminating with default action of signal 11 (SIGSEGV)
==19852==  Access not within mapped region at address 0x30
==19852==    at 0x4226DD: check (dictionary.c:57)
==19852==    by 0x4213F3: main (speller.c:112)
==19852==  If you believe this happened as a result of a stack
==19852==  overflow in your program's main thread (unlikely but
==19852==  possible), you can try to increase the size of the
==19852==  main thread stack using the --main-stacksize= flag.
==19852==  The main thread stack size used in this run was 8388608.
==19852== 
==19852== HEAP SUMMARY:
==19852==     in use at exit: 1,136 bytes in 2 blocks
==19852==   total heap usage: 143,093 allocs, 143,091 frees, 8,014,232 bytes allocated
==19852== 
==19852== LEAK SUMMARY:
==19852==    definitely lost: 0 bytes in 0 blocks
==19852==    indirectly lost: 0 bytes in 0 blocks
==19852==      possibly lost: 0 bytes in 0 blocks
==19852==    still reachable: 1,136 bytes in 2 blocks
==19852==         suppressed: 0 bytes in 0 blocks
==19852== Reachable blocks (those to which a pointer was found) are not shown.
==19852== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==19852== 
==19852== For counts of detected and suppressed errors, rerun with: -v
==19852== ERROR SUMMARY: 1564399 errors from 3 contexts (suppressed: 0 from 0)

Valgrind output for lalaland.txt

dictionary.c:57:17: runtime error: member access within null pointer of type 'node' (aka 'struct node')
==19852== 
==19852== Process terminating with default action of signal 11 (SIGSEGV)
==19852==  Access not within mapped region at address 0x30
==19852==    at 0x4226DD: check (dictionary.c:57)
==19852==    by 0x4213F3: main (speller.c:112)
==19852==  If you believe this happened as a result of a stack
==19852==  overflow in your program's main thread (unlikely but
==19852==  possible), you can try to increase the size of the
==19852==  main thread stack using the --main-stacksize= flag.
==19852==  The main thread stack size used in this run was 8388608.
==19852== 
==19852== HEAP SUMMARY:
==19852==     in use at exit: 1,136 bytes in 2 blocks
==19852==   total heap usage: 143,093 allocs, 143,091 frees, 8,014,232 bytes allocated
==19852== 
==19852== LEAK SUMMARY:
==19852==    definitely lost: 0 bytes in 0 blocks
==19852==    indirectly lost: 0 bytes in 0 blocks
==19852==      possibly lost: 0 bytes in 0 blocks
==19852==    still reachable: 1,136 bytes in 2 blocks
==19852==         suppressed: 0 bytes in 0 blocks
==19852== Reachable blocks (those to which a pointer was found) are not shown.
==19852== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==19852== 
==19852== For counts of detected and suppressed errors, rerun with: -v
==19852== ERROR SUMMARY: 1564399 errors from 3 contexts (suppressed: 0 from 0)
updated code
Source Link
Jake
  • 37
  • 5

My check function compiles, but gets stuck in a my while-loop when running. Using debugger, it looks like the values are set correctly for "word" in the node ("LA" from lalaland.txt), but the loop never breaks (Head is never NULL).

My thoughts / questions on whats wrong:

  1. Am I not iterating through the linked list correctly? head = head->next; should be doing this, but do I also need to change "word" in the "head" node?
  2. Would "head" as a node be null, or should I look for when head->next is null bc that would indicate end of list?

Thank you for direction in advance!

// Returns true if word is in dictionary, else false

bool check(const char *word)
{
    //int i;
    //Create new node, head
    node* head= malloc(sizeof(node));
    //Get hashtable value of word.
    hash_value = hash(word);
    //Set Head "Next" = hashtable valueCreate ofnew wordnode, making it pointhead to theuse firstas pointercursor into thattraverse linkedlist
   node head->next*head = hashtable[hash_value];
    //Set new node pointer, cursor, equal to head.
    //node *cursor = head;
    // ISSUE - thisLoop isto justlook repeatingfor andmatching repeatingwords
    while(head ->next!= NULL)
    {
      
   if(strcasecmp(head->word, word)==0)
    {
        return true;
    }
    else
    {
    head = head->next;
 
    }
    }
return false;
}

EDIT: Adding my structStruct code below

typedef struct node
{
    char word[LENGTH + 1];
    struct node* next;
}
node;
int hash_value = 1;
node* hashtable[15625];

My check function compiles, but gets stuck in a my while-loop when running. Using debugger, it looks like the values are set correctly for "word" in the node ("LA" from lalaland.txt), but the loop never breaks (Head is never NULL).

My thoughts / questions on whats wrong:

  1. Am I not iterating through the linked list correctly? head = head->next; should be doing this, but do I also need to change "word" in the "head" node?
  2. Would "head" as a node be null, or should I look for when head->next is null bc that would indicate end of list?

Thank you for direction in advance!

// Returns true if word is in dictionary, else false

bool check(const char *word)
{
    //int i;
    //Create new node, head
    node* head= malloc(sizeof(node));
    //Get hashtable value of word.
    hash_value = hash(word);
    //Set Head "Next" = hashtable value of word, making it point to the first pointer in that linkedlist
    head->next = hashtable[hash_value];
    //Set new node pointer, cursor, equal to head.
    //node *cursor = head;
    // ISSUE - this is just repeating and repeating
    while(head != NULL)
    {
        if(strcasecmp(head->word, word)==0)
    {
        return true;
    }
    else

    head = head->next;
 
    }
    return false;
}

EDIT: Adding my struct code below

typedef struct node
{
    char word[LENGTH + 1];
    struct node* next;
}
node;
int hash_value = 1;
node* hashtable[15625];

My check function compiles, but gets stuck in a my while-loop when running. Using debugger, it looks like the values are set correctly for "word" in the node ("LA" from lalaland.txt), but the loop never breaks (Head is never NULL).

My thoughts / questions on whats wrong:

  1. Am I not iterating through the linked list correctly? head = head->next; should be doing this, but do I also need to change "word" in the "head" node?
  2. Would "head" as a node be null, or should I look for when head->next is null bc that would indicate end of list?

Thank you for direction in advance!

// Returns true if word is in dictionary, else false

//Get hashtable value of word.
hash_value = hash(word);
//Create new node, head to use as cursor to traverse linkedlist
node *head = hashtable[hash_value];

//Loop to look for matching words
while(head->next!= NULL)
{
 
   if(strcasecmp(head->word, word)==0)
    {
        return true;
    }
    else
    {
    head = head->next;
    }
}
return false;

Struct code below

typedef struct node
{
    char word[LENGTH + 1];
    struct node* next;
}
node;
int hash_value = 1;
node* hashtable[15625];
Source Link
Jake
  • 37
  • 5

pset5 check - stuck in loop

My check function compiles, but gets stuck in a my while-loop when running. Using debugger, it looks like the values are set correctly for "word" in the node ("LA" from lalaland.txt), but the loop never breaks (Head is never NULL).

My thoughts / questions on whats wrong:

  1. Am I not iterating through the linked list correctly? head = head->next; should be doing this, but do I also need to change "word" in the "head" node?
  2. Would "head" as a node be null, or should I look for when head->next is null bc that would indicate end of list?

Thank you for direction in advance!

// Returns true if word is in dictionary, else false

bool check(const char *word)
{
    //int i;
    //Create new node, head
    node* head= malloc(sizeof(node));
    //Get hashtable value of word.
    hash_value = hash(word);
    //Set Head "Next" = hashtable value of word, making it point to the first pointer in that linkedlist
    head->next = hashtable[hash_value];
    //Set new node pointer, cursor, equal to head.
    //node *cursor = head;
    // ISSUE - this is just repeating and repeating
    while(head != NULL)
    {
        if(strcasecmp(head->word, word)==0)
    {
        return true;
    }
    else

    head = head->next;

    }
    return false;
}

EDIT: Adding my struct code below

typedef struct node
{
    char word[LENGTH + 1];
    struct node* next;
}
node;
int hash_value = 1;
node* hashtable[15625];