Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8340985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:20:10+00:00 2026-06-09T05:20:10+00:00

#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include dictionary.h #define HASH_SIZE

  • 0
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#include "dictionary.h"

#define HASH_SIZE 5

// prototype
int hash(char *word);

// counter
int counter;

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

// hash table
struct node *hashtable[HASH_SIZE];



/*
 * Returns true if word is in dictionary else false.
 */

bool
check(const char *word)
{
    //make a writable word (palabra)
    int len = strlen(word);
    char palabra[len + 1];
    //int i;

    // make la palabra all lowercase letters
    for ( int i = 0; i < len; i++)
    {
        if (isalpha(palabra[i]) || palabra[i] == '\'')
            palabra[i] = tolower(word[i]);
    }

    //palabra[i] = (char) "\0";

    // hash the word
    int value = hash(palabra);

    // let's look at the first node in the bucket
    struct node *n;
    if (hashtable[value] == NULL)
        return false;
    else
        n = hashtable[value];

    // iterate through the bucket to see if the word is there
    while (strcmp(palabra, n->word) != 0 && n->next != NULL)
    {
        n = n->next;
    }


    // if the word is found, print true, else false
    if ( strcmp(palabra, n->word) ==0 )
        return true;
    else
        return false;
}


/*
 * Loads dictionary into memory.  Returns true if successful else false.
 */

bool
load(const char *dictionary)
{
    // open the dictionary
    FILE *dict = fopen(dictionary, "r");
    if(dict == NULL)
    {
        printf("Could not open %s.\n", dictionary);
        return false;
    }

    // set all values in the hash table to null
    for(int i = 0; i < HASH_SIZE; i++)
    {
        hashtable[i] = NULL;
    }

    // set the counter to 0
    counter = 0;

    // iterate through the words in the dictionary
    while (!feof(dict))
    {
        //declare a node
        node *n = malloc( sizeof(node) );

        // copy the word into the node
        fscanf(dict, "%s", n->word);

        // hash the word, baby!
        int hash_value = hash(n->word);

        // start saving addresses to the hashtable
        n->next = hashtable[hash_value];
        hashtable[hash_value] = n;

        // that's one more!
        counter++;
    }

    // testing
    printf("Starting the test.\n");
    for ( int i = 0; i < HASH_SIZE; i++)
    {
        struct node *q = hashtable[i];
        while (q != NULL)
        {
            printf("%s\n", q->word);
            q = q->next;
        }
    }
    printf("Ending the test.\n");

    fclose(dict);

    return true;
}


/*
 * Returns number of words in dictionary if loaded else 0 if not yet loaded.
 */

unsigned int
size(void)
{
    return counter;
}


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

bool
unload(void)
{
    // TODO
    return false;
}


/*
 * Returns a hash value for a word.
 */

int
hash(char *word)
{
    // hash value and length of word
    int value = 0;
    int len = strlen(word);

    // iterate through letters, adding ASCII values
    for(int i = 0; i < len; i++)
    {
        int letter = (int) word[i];
        value += letter;
    }

    // make sure the value is less than 100 & return
    value = value%HASH_SIZE;
    return value;
} 

When I run my code, I receive this error message:

In file included from /usr/include/ctype.h:28:0,
from speller.c:10:
/usr/include/bits/types.h:31:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute‘ before ‘typedef’

Does this mean that I have somehow managed to alter the ctype.h library? If so, how do I fix it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T05:20:11+00:00Added an answer on June 9, 2026 at 5:20 am

    Aha! Gordon, you solved it! I found some stray characters typed just above the #include that were causing the problem. Thanks!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include dictionary.h #define HASH_SIZE 100 //
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<stdbool.h> char** parser(char *message) { char a[9][256]; char* tmp =message; bool
# include <stdio.h> # include <stdbool.h> # include <string.h> # include <stdlib.h> int main
Code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> typedef struct node { char*
#include<stdio.h> #include<stdlib.h> char* re() { char *p = hello; return p; } int main()
This is the code #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h>
#include<stdio.h> #include<string.h> #define USER_MEM (10*1024) typedef struct { unsigned short int vol_level; int mute_stat;
#include <stdio.h> #include <stdlib.h> #define calc(a,b) (a*b)/(a-b) void calculate(){ int a = 20, b
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> /*Define custom functions */ void insertElement(); bool elementExists();
#include <stdio.h> #include <stdlib.h> int main(void) { int x; int *in, *begin; in =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.