0

Hello All:

I want to create an array of structures like so:

#define MAX 10
struct hash_tbl {
int key;
int data;
};
struct hash_tbl hash_array[MAX],  *ptr;

Now, I am having some issues in attempting to "loop" through my
array of structures and just generate the some data for the fields:

for (i=0; i<=MAX_ADDR; i++) {

             sptr->key[i]  = (i * 100 + 13579);
             sptr->data[i] = (i * 100);
        }
printf("HASH KEY:==> %d DATA:==> %d\n", sptr[k]->key,
                                                        sptr[k]->data);

Results in:

keh_hash.c:31: error: subscripted value is neither array nor pointer
keh_hash.c:32: error: subscripted value is neither array nor pointer
keh_hash.c:41: error: invalid type argument of `->'
keh_hash.c:42: error: invalid type argument of `->'

So, could someone please assist on how I would walk through the creation of my array and how to print it out.

Thanks so much....!!!!!!!!!!!!

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by kxh29
0

what's a sptr

sptr->key = (i * 100 + 13579);

You don't have anything defined as a sptr...ptr yes but not sptr..

Plus your treating key like an array by using the [] but you have key defined as a structure member


struct hash_tbl {
int key;/*note not an array*/
int data;
};

Edited by gerard4143: n/a

0

Oh Sorry about that...! It should be just "ptr". And the array of
structures are built on line six(6).

struct hash_tbl hash_addr[MAX]

Thanks!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.