help

This is a discussion on help within the C Programming forums, part of the General Programming Boards category; Code: struct items_info{ string32 name; string128 description; }; struct interestpoint_info{ string32 name; string128 description; struct items_info items[3]; //struct interestpoint_info *interestpoint_item; ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    5

    help

    Code:
    struct items_info{
         string32 name;
         string128 description;
    };
    
    struct interestpoint_info{
         string32 name;
         string128 description;
         struct items_info items[3];
         //struct interestpoint_info *interestpoint_item;
    };
    
    struct gamelevel_info{
         string32 name;
         string128 description;
         struct interestpoint_info interestpoint[5];
         //struct gamelevel_info *level_interestpoint;
    };
    
    struct level{
         struct gamelevel_info gamelevel;
         struct level *nextlevel;      
    };
    
    void createlevel(struct level *map){
         
         int a, b;
         char choice;
         
         do{
         printf("\n\n");
         printf("----- CREATE LEVEL -----");
         while(map->nextlevel != NULL){
         map = map->nextlevel;
         }
         printf("\nName: "); scanf("%s", map->gamelevel.name);
         printf("\nDescription: "); scanf("%s", map->gamelevel.description);
         for(a = 0; a < 4; a++){
         printf("----- Interest Points -----");
         while(map->nextlevel.interestpoint[a] != NULL){
         map = map->nextlevel.interestpoint[a];
         }
         printf("\nName: "); scanf("%s", map->gamelevel.interestpoint[a].name);
         printf("\nDescription: "); scanf("%s", map->gamelevel.interestpoint[a].description);
         for(b = 0; b < 2; b++){
         printf("----- Items -----");
         while(map->nextlevel.interestpoint[a].items != NULL){
         map = map->nextlevel.interestpoint[a].items;
         }
         printf("\nName: "); scanf("%s", map->gamelevel.interestpoint[a].items[b].name);
         printf("\nDescription: "); scanf("%s", map->gamelevel.interestpoint[a].items[b].description);
         }
         }
         printf("Create New Level?\n");
         printf("Yes[Y] or No[N]"); scanf("%s", choice);
         }while(choice == 'Y' || choice == 'y');
         
    }
    How do I fix this error?

    request for member `interestpoint' in something not a structure or union

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,624
    Look at the code like
    Code:
    while(map->nextlevel.interestpoint[a] != NULL){
         map = map->nextlevel.interestpoint[a];
         }
    map->nextlevel is a pointer. Members of structs are accessed via pointers using the -> operator. So you need to access map->nextlevel->interestpoint[a].

    The next problem is that map->nextlevel->interestpoint[a] is of type struct interestpoint_info. It is not a pointer. A pointer can have a NULL value, but a struct cannot. So your comparison with NULL does not make sense.

    In summary, you need to be clear on what is a pointer in your code, and what is a data struct. You are mixing the concepts up, badly.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Sunshine, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

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