Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, I'm new to c-programming.while trying to access one structure member using infix operator,i'm getting errro message: [amit@localhost cprg]$ gcc -Wall -Werror struct.c struct.c: In function `main': struct.c:18: error: dereferencing ...
  1. #1
    Just Joined! amit4g's Avatar
    Join Date
    Feb 2007
    Location
    Bangalore,India
    Posts
    63

    Accesing structure member:Error:dereferencing pointer to incomplete type

    Hi,

    I'm new to c-programming.while trying to access one structure member using infix operator,i'm getting errro message:

    [amit@localhost cprg]$ gcc -Wall -Werror struct.c
    struct.c: In function `main':
    struct.c:18: error: dereferencing pointer to incomplete type

    [amit@localhost cprg]$ cat struct.c
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    /*Declaration of structure*/

    struct human
    {
    char *first;
    char gender[10];
    int age;
    } man, *p_human;

    struct man *p_man;
    int main(void)
    {
    strcpy(man.gender,"Male");
    printf("%s\n",man.gender);
    printf("%s\n",p_man->gender); <----------
    exit(EXIT_SUCCESS);
    }

    The "p_man" is pointer to structure "man".what am i missing here.

    Thanks,
    ~amit

  2. #2
    Just Joined! amit4g's Avatar
    Join Date
    Feb 2007
    Location
    Bangalore,India
    Posts
    63
    got the fix : ) from a different forum.

    struct man *p_man; <------- previous code

    struct human *p_man=&man; <----- updated code

    Thanks,
    ~amit

  3. #3
    Just Joined! amit4g's Avatar
    Join Date
    Feb 2007
    Location
    Bangalore,India
    Posts
    63
    sheer stupidity by me .(My applogy)
    declared a structure pointer and never assigned it to anything(should have assigned it to structure).

    Anyways,Better late than never : )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...