会员参考类型问题

时间:2014-01-08 23:05:18

标签: c linked-list

大家好,我的代码有问题,而且我真的不知道如何修复它。 它告诉我,会员参考类型' Word'(又名' struct dict_word *')不是结构或联合。 我试图将我的struct dict_word更改为word,就像我在typedef上看到的一样,但当我这样做时,它会给我这个错误。 如果你能向我解释一下,请看看我的代码我真的很感激。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct dict_word *word;
typedef struct node *Node;
typedef struct double_linked_list *DLL;
struct dict_word
{
    char words[100];
    int year[10];
    char eng_synonyms[100];
    char heb_synonyms[100];
};

struct node
{
    word data;
    Node *next;
    Node *previous;
};

struct double_linked_list
{
    Node *head;
    Node *last;
};

int SpliString(struct dict_word* entry, const char *str) // Here is where I'm trying to change struct dict_node to word
{
    long sz,j,k;

    int yearIndex;
    char *buffer;
    char *endOfYears;
    char *endOfYear;
    char *endOfDefinition;
    char *endOfWord = strstr(str, "_#_");

    //Sets the first num bytes of the block of memory pointed by ptr
    //to the specified value (related as an unsigned char)
    memset(entry, 0, sizeof(struct dict_word));



    if (endOfWord)
    {
        sz = endOfWord - str;

        strncpy(entry->words, str, sz);

        endOfYears = strstr(endOfWord+3, "_#_");

        if (endOfYears)
        {
            sz = endOfYears - (endOfWord+3);
            buffer = endOfWord+3;

            yearIndex = 0;
            j = 0;

            while(yearIndex<10 && buffer+j<endOfYears)
            {
                entry->year[yearIndex] = atoi(buffer+j);

                // check year for negative...
                if (entry->year[yearIndex]<=0)
                    return 0;

                // Locating substring
                endOfYear = strchr(buffer+j, '_');

                if (endOfYear)
                {
                    j = endOfYear - buffer;
                    j++;
                    yearIndex++;
                }
                else
                {
                    break;
                }
            }

            endOfDefinition = strstr(endOfYears+3, "_#_");

            if (endOfDefinition)
            {
                sz = endOfDefinition - (endOfYears+3);
                k = 0;

                for(j=0; j<sz; j++)
                {
                    if (endOfYears[j+3]==',')   //Q11: what's j+3?
                        //A11: skips _#_
                    {
                        entry->eng_synonyms[k] = ' ';
                        k++;
                    }
                    else if (endOfYears[j+3]>='a' && endOfYears[j+3]<='z')
                    {
                        entry->eng_synonyms[k] = endOfYears[j+3];
                        k++;
                    }
                    else if (endOfYears[j+3]!='_')
                    {
                        return 0;
                    }
                }

                k = 0;
                sz = (str+strlen(str)) - (endOfDefinition+3);

                for(j=0; j<sz; j++)
                {
                    if (endOfDefinition[j+3]==',')
                    {
                        entry->heb_synonyms[k] = ' ';
                        k++;
                    }
                    else if (endOfDefinition[j+3]>='A' && endOfDefinition[j+3]<='Z')
                    {
                        entry->heb_synonyms[k] = endOfDefinition[j+3];
                        k++;
                    }
                    else if (endOfDefinition[j+3]!='_')
                    {
                        return 0;
                    }
                }
            }

            // check for legality
            for(j=0;j<(int)strlen(entry->words);j++)

            {
                if (entry->words[j]<'a' || entry->words[j]>'z')
                    return 0;
            }

            return 1;
        }
    }
    return 0;
}

0 个答案:

没有答案