0

I keep getting the message that 'non-ASCII characters are not allowed outside of literals and identifiers.' I get this message when I compile and it is at the strcpy section. Any help gratefully accepted. program in C

// Implements a dictionary's functionality

#include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "dictionary.h"

// Represents number of buckets in a hash table
#define N 26

// Represents a node in a hash table
typedef struct node
{
    char word[LENGTH + 1];
    struct node *next;
}
node;

// declare words to count in dictionary
int dictionarysize = 0;

// Represents a hash table
node *hashtable[N];

// Hashes word to a number between 0 and 25, inclusive, based on its first letter
unsigned int hash(const char *word)
{
    return tolower(word[0]) - 'a';
}

// Loads dictionary into memory, returning true if successful else false
bool load(const char *dictionary)
{
    // Initialize hash table
    for (int i = 0; i < N; i++)
    {
        hashtable[i] = NULL;
    }

    // Open dictionary
    FILE *file = fopen(dictionary, "r");
    if (file == NULL)
    {
        unload();
        return false;
    }

    // Buffer for a word
    char word[LENGTH + 1];

    // Insert words into hash table
    while (fscanf(file, "%s", word) != EOF)
    {
        // TODO
        node *new_node = malloc(sizeof(node));
        if (new_node == NULL)
        {
            unload ();
            return false;
        }
        else
        {
            strcpy (new_node → word, word);
        }
        //implement hash function to get an index
        int index = hash(word);

        // if corresponding index in hashtable is empty, assign it to the new node
        // else append new node to the start of the linked list
        if (hashtable[index] == NULL
        {
            hashtable[index] = new_node;
        }
        else
        {
            new_node→next = hashtable [index];
            hashtable [index] = new_node;
        }
        dictionarysize++;
    }

    // Close dictionary
    fclose(file);

    // Indicate success
    return true;
}
''''''''''
1

This has to be one of the most unique syntax errors I've seen in a while! You get today's award for something almost never seen! ;-)

Let's look at one of the lines that are causing the problem:

        strcpy (new_node → word, word);

Now, look very closely at the arrow, This is a single character, a special character. It is NOT a dash - followed by the greater-than symbol >, or, together, ->. Note that this symbol is made up of two separate characters! This is what MUST be used, not the single-character arrow that you are using in the code!

Replace all those arrows and most of your issues should be resolved!

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

You must log in to answer this question.

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