globals.h

#ifndef _globals 

#define _globals 



#define DATA( L ) ( ( L ) -> datapointer ) 

#define NEXT( L ) ( ( L ) -> next ) 


typedef enum { OK, ERROR } status ; 
typedef enum { FALSE = 0 , TRUE=1 } bool ;  
typedef void *generic_ptr ; 

#endif

list.c

/*****************************************************************************/
/* list.c                                                                    */
/*                                                                           */
/*****************************************************************************/

#include <stdlib.h>
#include "globals.h"
#include "list.h"

status allocate_node( list *p_L , generic_ptr data)  {


  list L = (list) malloc(sizeof(node));

  if (L == NULL) return ERROR;

  *p_L = L;
  
  DATA(L) = data;
  NEXT(L) = NULL;
  return OK;

}


void free_node(list *p_L) {

  free(*p_L);
  *p_L = NULL;

}

status init_list( list *p_L) {

  *p_L = NULL;
  return OK;

}

bool empty_list(list L) {

  return (L == NULL ) ? TRUE : FALSE;

}

status insert( list *p_L,generic_ptr data ) {

  list L;
  
  if(allocate_node(&L, data) == ERROR) return ERROR;

  NEXT(L) = *p_L;
  *p_L = L; 
  return OK;

}

status append(list *p_L, generic_ptr data) {

  list L, tmplist;
  if(allocate_node(&L, data) == ERROR) return ERROR;

  if(empty_list(*p_L) == TRUE) *p_L = L;

  else {
    for(tmplist = *p_L; NEXT(tmplist) != NULL; tmplist=NEXT(tmplist) );
    NEXT(tmplist) = L;

  }

  return OK;

}

status delete(list *p_L, generic_ptr *p_data) {

  if(empty_list(*p_L)) return ERROR;

  *p_data = DATA(*p_L);

return delete_node(p_L, * p_L);

}

status delete_node( list *p_L, list node) {

  if(empty_list(*p_L) == TRUE) return ERROR;

  if(*p_L == node) *p_L = NEXT(*p_L);

  else {
    list L;
    for(L = *p_L; L != NULL && NEXT(L) != node; L = NEXT(L));

    if (L == NULL) return ERROR;
    else NEXT(L) = NEXT(node);

  }

  free_node(&node);
  return OK;

}




status traverse( list L, status(*p_func_f) () ) {

  if(empty_list(L)) return OK;

  if( (*p_func_f)(DATA(L)) == ERROR ) return ERROR;

  else
    return traverse(NEXT(L), p_func_f);

}


status find_key( list L, generic_ptr key, int(*p_cmp_f)(), list *p_keynode ) {

  list curr = NULL;
  
  while( ( curr = list_iterator(L, curr)) != NULL) {

    if ( (*p_cmp_f) (key, DATA(curr) ) == 0 ) {

      *p_keynode = curr;
      return OK;
    }
  }
  return ERROR;
}


list list_iterator(list L, list lastreturn ) {

  return (lastreturn == NULL) ? L : NEXT(lastreturn);

}


void destroy( list *p_L, void (*p_func_f)() ) {

  if (empty_list(*p_L) == FALSE) {

    destroy( &NEXT(*p_L), p_func_f );
    
    if (p_func_f != NULL) 
	
   (*p_func_f)(DATA(*p_L));
    
    free_node(p_L);

  }
}

list.h

#ifndef _list
#define _list

#include "globals.h"

typedef struct node node, *list;

struct node { generic_ptr datapointer; list next; };

extern status allocate_node( list *p_L, generic_ptr data ) ;

extern void   free_node( list *p_L ) ;

extern status init_list( list *p_L ) ;

extern bool   empty_list( list L ) ;

extern status insert( list *p_L, generic_ptr data ) ;

extern status append( list *p_L, generic_ptr data ) ;

extern status delete( list *p_L, generic_ptr *p_data ) ;

extern status delete_node( list *p_L, list node ) ;

extern status traverse( list L, status (*p_func_f) () );

extern status find_key( list L, generic_ptr key, int(*p_cmp_f) (), list *p_keynode );

extern list list_iterator( list L, list lastreturn );

extern void destroy(list *p_L, void (*p_func_f)() );

#endif

listinterface.c

#include <stdlib.h>
#include "listinterface.h"
#include "polynomial.h"
#include "globals.h"
#include "list.h" 
#include <stdio.h>

status term_insert( list *p_L , int coef , int deg ){ 

	term *p_term = (term *)malloc(sizeof(term)) ; 

	if (p_term == NULL)
		return ERROR ; 

	p_term->coefficient = coef ; 
	p_term->degree = deg ; 
	if(insert(p_L,(generic_ptr) p_term) == ERROR) { 

	free(p_term) ; 
	return ERROR ; 

   }
	return OK ; 

} 






status term_delete( list *p_L , int *p_coef , int *p_deg ) {

	term *p_term ; 
	
	if(delete(p_L,(generic_ptr *) &p_term) == ERROR ) 
		return ERROR ; 
	*p_coef = p_term->coefficient ;  
	*p_deg = p_term->degree ; 
	free(p_term) ; 
	return OK ; 

}

listinterface.h

#ifndef _listinterface 
#define _listinterface 

#include "list.h" 

extern status term_insert( list *p_L , int coef , int def ) ; 
extern status term_delete( list *p_L , int *p_coef , int *p_def ) ; 

#endif

polynomial.h

#ifndef _polynomial
#define _polnomial 

#include "list.h" 
#include "globals.h" 

typedef list polynomial ; 

typedef struct term { int coefficient ; int degree ; } term ; 

extern status read_poly(polynomial *p_poly) ; 

extern void write_poly(polynomial p_poly) ; 

extern status add_poly( polynomial *p_poly1 , polynomial *p_poly2) ; 

extern void destroy_poly( polynomial *p_poly ) ; 

extern status traverse(list L , status (*p_func_f)() );  
extern status find_key(list L , generic_ptr key, int (*p_cmp_f)() , list *p_keynode) ; 

extern list list_iterator( list L , list lastreturn ) ;

extern void destroy(list *p_L , void (*p_func_f)() );

#endif

Makefile

listinterface.o: listinterface.c globals.h list.h polynomial.h 
	gcc -ansi -Wall -pedantic -c listinterface.c 

list.o: list.c globals.h list.h 
	gcc -ansi -Wall -pedantic -c list.c 

clean: rm -f *.o

when i type make and hit enter it only makes listinterface.o when its supposed to make both listinterface.o and list.o

Recommended Answers

All 2 Replies

Try adding to the top of your make file

all: list.o listinterface.o

it worked! thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.