error: struct has no member named X

28,180

Look at the first error message of the compiler. It should complain about the *char in line 6, which should be char *.

By the way: always copy and paste error messages, so that we get the original messages.

Share:
28,180
Shaun1810
Author by

Shaun1810

Updated on February 14, 2020

Comments

  • Shaun1810
    Shaun1810 about 4 years
     #include <stdio.h>
     #include <stdlib.h>
    
     struct treeNode
     {
        *char word;
        int NumberCnt; 
        struct treeNode *rightPTR, *leftPTR; 
    
     };
     typedef struct treeNode node;
    
      node *rootPTR = NULL;
    
     void freeTree(node *currPTR)
     {
         if (currPTR!= NULL)
        {
            freeTree(currPTR -> leftPTR);
            free(currPTR);
            freeTree(currPTR -> rightPTR);
        }
     }
    
    void printTree(node *currPTR)
    {
        if (currPTR != NULL)
            {
                printTree(currPTR ->leftPTR);   
                printf("%d\n", currPTR->word);
                printTree(currPTR ->rightPTR);  
            }
    }
    
    
    
    int insertNode (char* input)
    {
    
        node *tempPTR = malloc(sizeof(node));
        tempPTR -> word = input;
        tempPTR -> NumberCnt=0;
        tempPTR -> leftPTR = NULL;
        tempPTR -> rightPTR = NULL;
    
        if (rootPTR == NULL)
        {   
            rootPTR = tempPTR;
            rootPTR -> NumberCnt++;
        }
         else 
        {
            int comp;
            node *currPTR = rootPTR;
            node *prevPTR = NULL;
    
                while (currPTR != NULL)
                {
                    comp = strcmp(input, (currPTR->word));
                    if (comp = 0)
                    {
                        printf ("Entry already exists");
                        return 1;   
                    }
                    else if (comp < 0)
                    {
                        prevPTR = currPTR;
                        currPTR = currPTR->leftPTR;
                    }
                    else if (comp > 0)
                    {
                        prevPTR = currPTR;
                        currPTR = currPTR->rightPTR;
                    }
    
                }
    
            comp = strcmp(input, (prevPTR ->word));
            if (comp < 0)
            {
                prevPTR->leftPTR = tempPTR;
    
            }
    
            else if (comp > 0)
            {
                prevPTR->rightPTR = tempPTR;
    
            }
    
            return 0;   
        }
    
        return 2;
    }
    
    int search(char* input) 
    {
         if (input == rootPTR ->data)
        {
            printf("Node found %d\n", rootPTR->data);
            return 0;
        }
        else
        {
            if (input < rootPTR ->data)
                {
    
                    node *currPTR = rootPTR->leftPTR;
    
                    while (currPTR != NULL)
                     {
                        if (input == currPTR->data)
                        {
                            printf("Node found %d\n", currPTR->data);
                             return 0;
                         }
                        else if (input < currPTR->data)
                        {
                            currPTR = (currPTR -> leftPTR); 
                        }
                        else if (input > currPTR->data)
                        {
                            currPTR = (currPTR -> rightPTR);
                         } 
                    }
                    printf ("Node not in tree\n");
                    return 1;
                }
    
                 if (input > rootPTR ->data)
                {
    
                    node *currPTR = rootPTR->rightPTR;
    
                    while (currPTR != NULL)
                    {
    
                        if (input == currPTR->data)
                        {
                            printf ("Node found %d\n", currPTR->data);
                            return 0;
                        }
    
                        else if (input < currPTR->data)
                        {
                            currPTR = (currPTR -> leftPTR); 
                        } 
    
                        else if (input > currPTR->data)
                        {
                            currPTR = (currPTR ->rightPTR);
                        }
                    }
                    printf ("Node not in tree\n");
                    return 1;
                }
    
        }
    
    return 2;
    }
    
    void fixWord(char* buff)
    {
        char* unfixed = buff;
        char* fixed = buff;
    
        while (*unfixed)
        {
    
                if (isalpha(*unfixed))
            {
                *fixed=tolower(*unfixed);
                    *fixed++;
    
            }   
                *unfixed++;
    
    
        }
        *fixed=0;
    
    }
    
    
    int main()
    {   
        FILE *ptr_file;
        char buff [100];
      //ptr_file = fopen ("sherlock.txt", "r");
        ptr_file = fopen ("input.txt", "r");
        if (!ptr_file)
            printf("File read error");
    
    
            while(fscanf(ptr_file, "%s ", buff ) != EOF)
            {
                int comparison = strcmp(buff, "endoffile");
                if (comparison == 0)
                {
                    return 0;
                }
    
                 fixWord(buff);
                 insert(buff);
            }
    
        fclose(ptr_file);
    
    }
    

    I have this code which is a binary tree which reads in text from a file and then adds it to a binary tree. I have a struct to represent a new node which takes in a string and a integer which increments to show word count. I originally had this tree set up to take in integers to test the tree functionality and it worked just fine, however since updating my struct to take in the string and the incremented integer the compiler is complaining the struct does not longer contains any of the members of the struct. I have no idea why this happening.