We help IT Professionals succeed at work.
Get Started

Mystified by error message

GPicasso
GPicasso asked
on
366 Views
Last Modified: 2012-05-12
Hey I have been debugging this code all day and am unable to figure out my error messages.  everything but the main program will work.  
I have included all the code and the error messages.  I need to have this at least print out using a list.  Any help is appreciated.
 error-messages
/*fatal.h*/
#include <stdio.h>
#include <stdlib.h>

#define Error( Str )        FatalError( Str )
#define FatalError( Str )   fprintf( stderr, "%s\n", Str ), exit( 1 )

Open in new window

/*list.h*/       

 typedef int ElementType;

        #ifndef _List_H
        #define _List_H

        struct Node;
        typedef struct Node *PtrToNode;
        typedef PtrToNode List;
        typedef PtrToNode Position;

        List MakeEmpty( List L );
        int IsEmpty( List L );
        int IsLast( Position P, List L );
        Position Find( ElementType X, List L );
        void Delete( ElementType X, List L );
        Position FindPrevious( ElementType X, List L );
        void Insert( ElementType X, List L, Position P );
        void DeleteList( List L );
        Position Header( List L );
        Position First( List L );
        Position Advance( Position P );
        ElementType Retrieve( Position P );

        #endif

Open in new window

#include <stdio.h>
#include <stdlib.h>
#include "list.h"
/*main*/

void print_list(List root) {
int i = 0;  

while (root) {
    printf("%c ", Find(i, root));
    i++;
  }
  printf("\n");
}
/*
Node* reverse(Node* root) {
  Node* new_root = 0;
  while (root) {
    Node* next = root->next;
    root->next = new_root;
    new_root = root;
    root = next;
  }
  return new_root;
}*/

List reverse(List* root){
List new_root;
int x = First(*root);
int y;
int i = 1;
while (root){
new_root = x;
y = Find(i, root);
x = y;
i++;
}
return new_root;

int main() {
List* root;
Insert(1, root, 0);
Insert(2, root, 1);
Insert(3, root, 2);
Insert(4, root, 3);
  /*Node d = { 'd', 0 };
  Node c = { 'c', &d };
  Node b = { 'b', &c };
  Node a = { 'a', &b };

  Node* root = &a;*/
  print_list(root);
  root = reverse(root);
  print_list(root);

  return 0;
}

Open in new window

/*list.c*/
#include "list.h"
	#include <stdlib.h>
	#include "fatal.h"

	
	struct Node
	{
	ElementType Element;
	Position    Next;
	};

	List
	MakeEmpty( List L )
	{
	if( L != NULL )
	DeleteList( L );
	L = malloc( sizeof( struct Node ) );
	if( L == NULL )
	FatalError( "Out of memory!" );
	L->Next = NULL;
	return L;
	}


	int
	IsEmpty( List L )
	{
	return L->Next == NULL;
	}


	int IsLast( Position P, List L )
	{
	return P->Next == NULL;
	}

	Position
	Find( ElementType X, List L )
	{
	Position P;

	      P = L->Next;
	      while( P != NULL && P->Element != X )
	          P = P->Next;

	     return P;
	}
	


	void
	Delete( ElementType X, List L )
	{
	Position P, TmpCell;

	P = FindPrevious( X, L );

	if( !IsLast( P, L ) )  
	{                     
	TmpCell = P->Next;
	P->Next = TmpCell->Next;  
	free( TmpCell );
	}
	}


	Position
	FindPrevious( ElementType X, List L )
	{
	Position P;

	      P = L;
	      while( P->Next != NULL && P->Next->Element != X )
	          P = P->Next;

	      return P;
	}
	

	void
	Insert( ElementType X, List L, Position P )
	{
	Position TmpCell;

	      TmpCell = malloc( sizeof( struct Node ) );
	      if( TmpCell == NULL )
	          FatalError( "Out of space!!!" );

	      TmpCell->Element = X;
	      TmpCell->Next = P->Next;
	      P->Next = TmpCell;
	}
	

	


	void
	DeleteList( List L )
	{
	Position P, Tmp;

	     P = L->Next;  
	      L->Next = NULL;
	      while( P != NULL )
	{
	         Tmp = P->Next;
	          free( P );
	          P = Tmp;
	}
	}
	

	Position
	Header( List L )
	{
	return L;
	}

	Position
	First( List L )
	{
	return L->Next;
	}

	Position
	Advance( Position P )
	{
	return P->Next;
	}

	ElementType
	Retrieve( Position P )
	{
	return P->Element;
	}

Open in new window

Comment
Watch Question
This problem has been solved!
Unlock 3 Answers and 5 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE