0

Ihave been trying to test my load function separately,since I have not implemented other functions,size,check,unload . I have got the following Clang error " expected identifier". I do not know how to eliminate this error.Any help in this regard will be appeciated. I have also another question. When we use a hash table, how do we ensure we check for collisions? Everytime that we calculate a new value using the hash function,do we check that value with all the earlier values calculated. I thought this would be very inefficient. Hence there must be a quicker way to detect collisions in the hash Table. uma1966

/**************************************************************************** * dictionary.c * * Computer Science 50 * Problem Set 5 * * Implements a dictionary's functionality. ***************************************************************************/

#include <stdbool.h>

#include "dictionary.h"
#include <stdio.h>

/**
 * Returns true if word is in dictionary else false.
 */
bool check(const char* word)
{

   int strcmp(const char *text, const char *dictionary); 

    return false;
}

/**
 * Loads dictionary into memory.  Returns true if successful else false.
 */
bool load(const char* dictionary);

// load dictionary       

{FILE* fp = fopen(dictionary, "r");
if (fp == NULL)
{
    printf("Couldn't open %s.\n", dictionary);
    return false;  

}
array   key;

key=*dictionary;

int hash_function(char* key); 
int size2;

key=atoi(key[0]);

int hash=key;
 return hash%size2;
// mod by size to stay w/in bound of table




{


   typedef struct node

   {
   char LENGTH;
    char word[LENGTH+1];
    struct node* next;

   }
   node;

   typedef struct node 


   {

    char word[LENGTH+1];
    struct node* next;

   }
   node*  hashtable[500];
   new_node->next=head;
   // malloac a node* for each new_word
   node*  new_node=malloc(size of node);
   fscanf(file,"%s",new_node->word);

   while (cursor!=NULL)
     {
        cursor=cursor->next;

      }

    return false;
}

/**
 * Returns number of words in dictionary if loaded else 0 if not yet loaded.
 */
unsigned int size(void)
{
    // TODO

    return 0;
}

/**
 * Unloads dictionary from memory.  Returns true if successful else false.
 */

Clang error

clang -ggdb3 -O0 -Qunused-arguments -std=c99 -Wall -Werror -c -o dictionary.o dictionary.c dictionary.c:33:5: error: expected identifier or '(' {FILE* fp = fopen(dictionary, "r"); ^ 1 error generated. make: *** [dictionary.o] Error 1 jharvard@appliance (~/Dropbox/pset5):

1 Answer 1

0

The error is because you have a semicolon on the end of the load signature. Take it out and the error should go away.

The pset and the existing code was designed so that you could create each function in order and test without having to implement the remaining functions, with load() being the first to be implemented, followed by check, size and finally unload.

As for collisions, a perfect hash (no collisions) is inefficient. That's why we usually will hash a word (using the hash of your choosing) and make a linked list for each hash value. If there's no previous word for that hash, then we just plug the word in at the beginning of a list. If there's already one or more words with a given hash value, i.e., we detect a collision, then we just add the new word to the list.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

1
  • Thanks .your suggestion fixed that error. I have several other errors . I must slowly try to fix them.
    – uma1966
    Commented Dec 20, 2015 at 18:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .