Dereferencing Pointer

This is a discussion on Dereferencing Pointer within the C Programming forums, part of the General Programming Boards category; Hi, I have created a BankID structure with an int and char * parameter. And, I m trying to access ...

  1. #1
    Unregistered
    Guest

    Angry Dereferencing Pointer

    Hi,

    I have created a BankID structure with an int and char * parameter.

    And, I m trying to access this int and char parameter of this structure.

    i have created an instance of this structure as bankID *bankid1;

    I am trying to access this as bankid1->pass(which is int!)////

    but, i get the error - DEFERENCING POINTER TO AN INCOMPLETE TYPE !!

    What does this mean ??

    How can i solve this??

    Thanks,

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,803
    Have you actually created an instance of the struct to have your pointer variable point to? Just creating a pointer variable to a struct doesn't magically create a struct for you. Where does "bankid1" point to if it is a pointer? Nowhere if don't tell it yourself. If you are going to be using a pointer to the struct, you need to do something like:
    Code:
    struct bankID *bankid1 = (struct bankID*) malloc(sizeof(struct bankID));
    bankid1->pass = 10;
    This will actually create a structure dynamically and assign the address of the struct to your pointer variable.

    Or, you can forget the pointer and just create an actual struct variable and access the members like so:
    Code:
    struct bankID bankid1;
    bankid1.pass = 10;
    Hopefully this should help you out a bit.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    27
    Hi,
    It seems that you have created a pointer to BankID rather than an instance of a BankID.

    Try

    BankID bankid1;

    /*if you need a pointer then add */

    BankID *bankidp;
    bankidp = &bankid1;

    Below is another method.

    BankID *bankid1;
    bankid1 = (BankID *)malloc(sizeof(BankID));

    Hope this helps.

    BTW: If you use memory allocation do not forget to free the memory;
    Pappy
    You learn something new everyday.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  3. Ban pointers or references on classes?
    By Elysia in forum C++ Programming
    Replies: 89
    Last Post: 10-30-2007, 03:20 AM
  4. Question About Pointer To Pointer
    By BlitzPackage in forum C++ Programming
    Replies: 2
    Last Post: 09-19-2005, 10:19 PM
  5. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 01:19 AM

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