I have a function to insert an element to a hash table like this in my program:
void insert(int key,int data)
{
    struct DataItem *newdata = (struct DataItem*) malloc(sizeof(struct DataItem));
    int  hashIndex;
    newdata->key = key;
    newdata->data = data;
    hashIndex = hashCode(key);
    while(hashArray[hashIndex] != NULL && hashArray[hashIndex]->key != -1)
    {
        ++hashIndex;
        hashIndex %= MAX_SIZE;
    }   
    hashArray[hashIndex] = newdata;
}
This works without any problem. However, when I change the position of the condition in while loop to this:
while(hashArray[hashIndex]->key != -1 && hashArray[hashIndex] != NULL )
There ís an "Segmentation Fault" error. And the program pointer stops at the while loop when I call the insert function.
I'm wondering what is the problem?
 
     
     
     
    