C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-26-2002, 08:01 AM   #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
CyC|OpS is offline   Reply With Quote
Old 10-26-2002, 08:37 AM   #2
Registered User
 
Join Date: Dec 2001
Posts: 25
anyone?
CyC|OpS is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 10:29 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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