struct question

This is a discussion on struct question within the C Programming forums, part of the General Programming Boards category; answered...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    569

    struct question

    answered
    Last edited by -EquinoX-; 04-14-2008 at 04:16 PM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    The error message "left side of -> is not a pointer to struct or union" (details may vary) should tell you that the left side of ->, namely rule, is not a pointer to a struct. It is itself a struct; so you need to use rule.target to access members.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    if I declare rule_t* rule then this would work right?

  4. #4
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    edited
    Last edited by -EquinoX-; 04-14-2008 at 12:47 AM.

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You declare rules to be a pointer to a rule_t. That's fine and good, but at the moment rules points to somewhere just outside of Hoboken, and then when you try to access rules->dependency on the next line, the Mafia comes and gets you.

    If you want to actually have a rule, you need to either malloc one for rules to point at, or declare one.

  6. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    I see.. so the reason why is because I haven't declare rule_t?? how do I declare one?

  7. #7
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    oh and one more thing, when I put HashTable = HashTableConstuct(50);

    it gives me this error:

    /tmp/ccGGLIcr.o: In function `main':
    memake.c.text+0x52): undefined reference to `HashTableConstruct'
    collect2: ld returned 1 exit status

    I already include the "hash.h" which is the interface of the hash table.. why wouldn't it work?

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by -EquinoX- View Post
    I see.. so the reason why is because I haven't declare rule_t?? how do I declare one?
    by
    Code:
    rule_t rule; /* this is a rule_t */
    as opposed to
    Code:
    rule_t *rule; /* this will point to a rule_t, if I ever have one to point to */

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by -EquinoX- View Post
    oh and one more thing, when I put HashTable = HashTableConstuct(50);

    it gives me this error:

    /tmp/ccGGLIcr.o: In function `main':
    memake.c.text+0x52): undefined reference to `HashTableConstruct'
    collect2: ld returned 1 exit status

    I already include the "hash.h" which is the interface of the hash table.. why wouldn't it work?
    Note the "ld returned" which means we're dealing with the linker. It compiled just fine -- but you need to include the library itself. Do you have the source for HashTableConstruct? If so, add it to the project. Do you only have the binaries (in .o, .obj, .lib, .dll, .a, or .so form)? If so, you'll need to link it in using the -l switch (on gcc, I forget what it is on MSVC).

  10. #10
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    what do you mean the source for HashTableConstruct? you mean the .c file??

  11. #11
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by -EquinoX- View Post
    what do you mean the source for HashTableConstruct? you mean the .c file??
    That would be the source code, yes.

  12. #12
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    hmm..doesn't it seem weird to include the .c file?? should including the .h file works?

  13. #13
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You don't include the .c file using #include; but you do need to turn that source into executable code!

  14. #14
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    I don't understand what you mean.. sorry

  15. #15
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You have a .c file with code in for HashWhateverItWas(), right? You need to compile that file too. If you have a reasonable IDE, it will handle it for you if you create a "project" (or maybe "solution") and put all the files in it.

Page 1 of 4 1234 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with linked list sorting function
    By Jaggid1x in forum C Programming
    Replies: 6
    Last Post: 06-02-2009, 03:14 AM
  2. Struct question... difference between passing to function...
    By Sparrowhawk in forum C++ Programming
    Replies: 6
    Last Post: 02-23-2009, 03:59 PM
  3. Looking for a way to store listbox data
    By Welder in forum C Programming
    Replies: 20
    Last Post: 11-02-2007, 12:48 AM
  4. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  5. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 02:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21