View Single Post
  #4 (permalink)  
Old April 6th, 2006, 12:44 AM
C@uark C@uark is offline
Authorized User
 
Join Date: Oct 2004
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to C@uark
Default

change:
entry = (unsigned short *) calloc(2, sizeof (code));

you have declared "entry" as a pntr to a code1 structure so when you call calloc type cast it to the appropriate type.
entry = ( struct code1* ) calloc(2, sizeof (code)); // >>first arg is the number of elements in an array you
                                                    //wish to allocate.<<
                                                    // >>second arg is the size of each element, in
                                                 // in this case the size of a code1/code structure.<<
calloc always returns a void pntr or NULL if insufficient memory, you must type cast it to the type of the receiving variable in this case a struct code1*.
Now since you have dynamically allocated the memory for "entry" you would also dereference the structure member variables by using the indirect access operator -> i.e. entry[i]->key[0] = key1[0]; // i being the subscript into the array of structs that you have allocated
Reply With Quote