Thread: inputFn with hash not assigning pointer correctly

  1. #1
    Registered User
    Join Date
    May 2002

    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.
    typedef struct
    	char flightNum[8];
    	char city[20];
    	int price;
    	int search_count; //used later for heap
    	char depTime[6];
    and i have a hashed array which is a array of HASH structs.
    typedef struct
    	void *dataPtr; //this is the pointer that is not being assigned correctly, pointing to DATA, or atleast meant to
    	int flag;

    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

    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);
    thanks mates
    Last edited by mackol; 11-22-2002 at 11:09 PM.

  2. #2
    Registered User
    Join Date
    May 2002
    dont worry. i solved the problem

    the error was using the idea of making dataptr of type void *

    it should have been of type DATA *

    thanks anyways
    i am leaving the question just in case ppl like to read code

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why does C need pointer conversion
    By password636 in forum C Programming
    Replies: 2
    Last Post: 04-10-2009, 07:33 AM
  2. Replies: 5
    Last Post: 04-04-2009, 03:45 AM
  3. Ban pointers or references on classes?
    By Elysia in forum C++ Programming
    Replies: 89
    Last Post: 10-30-2007, 03:20 AM
  4. sorting with pointer of pointers to array
    By dunpealslyr in forum C++ Programming
    Replies: 6
    Last Post: 10-01-2007, 11:26 PM
  5. file pointer
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-11-2001, 03:52 PM