half ADT (nested struct) problem...

This is a discussion on half ADT (nested struct) problem... within the C Programming forums, part of the General Programming Boards category; Hi, I ve got problem in implementing ADT in my program, below I posted my PQ.c, PQ.h -> which is ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    25

    half ADT (nested struct) problem...

    Hi,

    I ve got problem in implementing ADT in my program,
    below I posted my PQ.c, PQ.h -> which is the ADT (not full ADT) you'll see why in my code...and office.c+ office. which is the program using the functions implemented in PQ

    this is the code (not full code, but will gives you the idea of my problem):

    PQ.h
    Code:
    typedef struct workers PQItem;
    //typedef WRecord PQItem;
    struct pqueue
    {
    	int	size;
    	PQItem	*item;
    };
    
    typedef struct pqueue PQ;
    
    PQ *initPQ( void );
    void swapArray( PQItem *arr1, PQItem *arr2 );
    PQ.c
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include "PQ.h"
    
    PQ *initPQ( void )
    {
    	
    	PQ *pq;
    
    	pq = malloc ( sizeof(PQ) );
    
    	if( pq == NULL )
    	{
    		fprintf( stderr, "ERROR: Memory allocation for priority queue failed;"
    			       "program terminated.\n" );
    		exit( EXIT_FAILURE );
    	}
    
    	return pq;
    
    }
    
    void swapArray( PQItem *arr1, PQItem *arr2 )
    {
    
    	PQItem temp;
    
    	temp = *arr1;
    	*arr1 = *arr2;
    	*arr2 = temp;
    
    	return;
    
    }
    office.h
    Code:
    #include "PQ.h"
    #define  NAMESIZE  100
    #define	 BASE	   100
    
    	/* Structure Template */
    
    typedef int Time;
    
    struct workers
    {
    	char  *name;
    	Time  starttime;
    	Time  stoptime;
    };
    
    typedef struct workers WRecord;
    //typedef struct workers PQItem;
    
    	/* Functions Prototype */
    void usage( char *progname );
    FILE *open_file( char *progname, char *fname, const char *mode );
    char *alloc_string_memory( int len );
    char *get_name( FILE *fp );
    WRecord *read_worker( FILE *fp, int workers_total );
    Time add_time( Time time1, Time time2);
    office.c
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include "office.h"
    
    int main (argc....)
    {
        /* main program here, not related with problem */
    }
    
    /*functions here (from function prototype declared in office.h, which is not related as well IMO */
    My problem is PQItem, where it is the same type as struct workers, but I dont know how to linked the files therefore PQ recognize struct workers (or PQItem or WRecord), there in my program you'll see two appearences of

    Code:
    typedef struct workers PQItem;
    one with // and without...that's one the combination I ve tried to make the linking work..

    but so far what I ve get is these error:
    - redefinition error
    -or no semicoolon at the end of the struct
    -or pointer redeferencing into INCOMPLETE type (this is in swapArray functions in PQ.c, where it doesnt recognize PQItem, and I believe this is the problem, HOW to make PQItem recognized??)

    i hope someone can help me or gimme any suggestion,
    I dont need full ADT...just semi ADT

    thanks

    Ferdinand

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    25
    anyone?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. very weird problem (pointers I think)
    By hannibar in forum C Programming
    Replies: 2
    Last Post: 10-11-2005, 06:45 AM
  2. Struct Problem
    By Mr.Modem in forum C Programming
    Replies: 5
    Last Post: 08-13-2005, 03:19 PM
  3. Problem constructing a class with a nested struc
    By pliang in forum C++ Programming
    Replies: 3
    Last Post: 04-14-2005, 07:43 PM
  4. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 05:58 PM
  5. Bi-Directional Linked Lists
    By Thantos in forum C Programming
    Replies: 6
    Last Post: 12-11-2003, 09:24 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21