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