inputFn with hash not assigning pointer correctly
well, the topic says a bit
getting input from a file
sampe input
<string>flight num <string> city <int>price <string>time
my key is the flight number
i have a DATA node where all my data gets stored via dynamic allocation.
Code:
typedef struct
{
char flightNum[8];
char city[20];
int price;
int search_count; //used later for heap
char depTime[6];
}DATA;
and i have a hashed array which is a array of HASH structs.
Code:
typedef struct
{
void *dataPtr; //this is the pointer that is not being assigned correctly, pointing to DATA, or atleast meant to
int flag;
}HASH;
now i am trying to print but it doesnt seem like it recognizes the fact that void *dataPtr is pointing to anything :(
can anyone point out whats going wrong please :)
Code:
void inputFn(HASH hashAry[],
FILE* fpInput)
{
char dataIn[8];
int index;
int i = 0;
DATA* temp;
char tempStr[20];
while(fscanf(fpInput,"%s", dataIn) != EOF)
{
index = hashFn(dataIn);
while(hashAry[index].flag == NOTEMPTY)
{
index = CRA(index);
}
hashAry[index].flag = NOTEMPTY;
temp = (DATA*)malloc(sizeof(DATA));
strcpy(temp->flightNum, dataIn);
fscanf(fpInput, "%s", tempStr);
strcpy(temp->city, tempStr);
fscanf(fpInput, "%d", &(temp->price));
fscanf(fpInput,"%s", tempStr);
strcpy(temp->depTime, tempStr);
hashAry[index].dataPtr = temp; //i suspect this line doesnt work
printf("%s\n", temp->flightNum);
printf("%s\n", hashAry[index].dataPtr->city);
}
return;
}
thanks mates :)