0

I have been trying to test load function separately (Using Zamyla video for some guidance). I have watched this tape several times, but still unable to load function without compiler errors. I am giving below my c program and Clang Compiler Errors.

/**
 * dictionary.c
 *
 * Computer Science 50
 * Problem Set 5
 *
 * Implements a dictionary's functionality.
 */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdbool.h>
#include "dictionary.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)
{
    FILE* fp = fopen(dictionary, "r");
    if (fp == NULL)
    {
        printf("Couldn't open %s.\n", dictionary);
        return false;
    }
    char word;
    char new_node;
    dictionary =&word;
    int hash_function( char* key);      
    int size2=500;
    int i=0;

    char  key=word;
    int   hash=toupper(key[0])-'A';
    return hash%size2;
   // mod by size to stay w/in bound of table

   char *head;
   char *next;
   char *cursor; 
   typedef struct node; 
   {
       char word[LENGTH+1];
       struct node* next;
   }
   struct node*  hashtable[500];
   new_node->next=head;
   // malloac a node* for each new_word
   struct  node*  new_node=malloc(size of node);
   fscanf(dictionary,"%s",new_node->struct word);     
   while (cursor!=NULL)
   {
       cursor=cursor->next;
   }
   i++;        
   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.
 */
// TO DO
return false;

.

jharvard@appliance (~/Dropbox/pset5): make clang -ggdb3 -O0 -Qunused-arguments -std=c99 -Wall -Werror -c -o dictionary.o dictionary.c

dictionary.c:57:25: error: subscripted value is not an array, pointer, or vector
int hash=toupper(key[0])-'A';
                 ~~~^~

dictionary.c:67:8: error: typedef requires a name [-Werror,-Wmissing-declarations]
typedef struct node;
        ^~~~~~~

dictionary.c:70:14: error: unused variable 'word' [-Werror,-Wunused-variable]
char word[LENGTH+1];
     ^

dictionary.c:71:22: error: unused variable 'next' [-Werror,-Wunused-variable]
struct node* next;
             ^ 

dictionary.c:75:18: error: member reference type 'char' is not a pointer
new_node->next=head;
~~~~~~~~^ 

dictionary.c:77:22: error: redefinition of 'new_node' with a different type: 'struct node *' vs 'char'
struct  node* new_node=malloc(size of node);
              ^ 
dictionary.c:45:9: note: previous definition is here    
char new_node;
     ^ 

dictionary.c:77:43: error: expected ')'
struct  node*  new_node=malloc(size of node);
                                    ^ 
dictionary.c:77:37: note: to match this '('
struct  node*  new_node=malloc(size of node);
                              ^ 

dictionary.c:78:41: error: expected identifier
fscanf(dictionary,"%s",new_node->struct word);
                                 ^

dictionary.c:82:26: error: member reference base type 'char' is not a structure or union
cursor=cursor->next;
       ~~~~~~^ ~~~~

dictionary.c:106:9: error: expected identifier or '('
return false;
^ 

10 errors generated. make: *** [dictionary.o] Error 1 

jharvard@appliance (~/Dropbox/pset5):

Particularly I do not understand the used errors for word, next etc and how can I char word key into a string or pointer etc.

Obviously I am missing some basic points to get this load function. While I understand basic pointer notation,I do not follow what char* key means in int hash_function(char* key) in the website study.cs50.net/hashtables.

Any help or guidance to read the material that will help me to resolve the present Clang errors will be appreciated. Uma1966

2
  • Particularly I do not understand the errors for unused words word,next etc and how can I change char word key into a string or pointer etc.
    – uma1966
    Commented Dec 22, 2015 at 5:10
  • Please review the following link and then edit your question into a more readable format. Thanks. meta.stackexchange.com/questions/22186/…
    – Cliff B
    Commented Dec 22, 2015 at 6:38

0

You must log in to answer this question.

Browse other questions tagged .