Thread: array of void pointers problem

  1. #1
    Registered User
    Join Date
    Nov 2011

    array of void pointers problem

    I need to implement a Trie using an array of void pointers. I've been staring at my screen for a while now. I know I'm missing something (possibly, trivial) but I can't figure this out.

    I have the following 3 kinds of struct
    typedef struct NodeTag{
    void* key[27];
    }Node; typedef struct InfoTag{
    void* word;
    int frequency;
    }Info; typedef struct{
    Node* root;
    What I want to achieve with my struct is this:
    - Trie points to Node
    - Node can either point to
    • another Node
    • or Info
    Here is part of my code. It's not doing anything useful but I'm going crazy over the array of void pointers.
    int Insert(Trie *trie, char *input, int freq)
    int frequency; Node* ptrNode; Info* ptrInfo; if(trie->root == NULL)
    trie->root = (Node*) malloc(sizeof(Node));
    ptrNode = trie->root; if(ptr->key[input[index] - 'a'] == NULL) {
    ptrInfo = (Info*)malloc(sizeof(Info)); ptrInfo->frequency = freq; ptr->key[input[index - 'a']] = (Info*) ptrInfo; frequency = ptr->key[input[index] - 'a']->frequency
    } }
    Error when compiling(line causing error is in red):
    assign2Funcs.c: In function ‘Insert’:
    assign2Funcs.c:34:41: warning: dereferencing ‘void *’ pointer [enabled by default]
    assign2Funcs.c:34:41: error: request for member ‘frequency’ in something not a structure or union

    Thanks in advance

  2. #2
    Registered User
    Join Date
    Oct 2011
    It is really hard to understand what you want to do without the entire code, but I think what you should do is first dereference "key[input[index] - 'a']" into an Info structure pointer, and then access the frequency field with this new pointer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with Pointers and array
    By platoali in forum C++ Programming
    Replies: 2
    Last Post: 01-07-2011, 02:04 PM
  2. void* pointers
    By Drogin in forum C Programming
    Replies: 6
    Last Post: 09-04-2009, 11:04 AM
  3. Array of pointers problem
    By Ryukugan in forum C++ Programming
    Replies: 1
    Last Post: 06-04-2009, 01:51 PM
  4. Problem with Pointers and an Array
    By thetinman in forum C Programming
    Replies: 1
    Last Post: 05-10-2007, 02:20 PM
  5. array of pointers problem
    By StevenGarcia in forum C++ Programming
    Replies: 4
    Last Post: 11-17-2006, 09:48 PM

Tags for this Thread