Thread: Linked List from Standard Input

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    18

    Unhappy Linked List from Standard Input

    Hi all,

    for any of you who shiver at ignorant, terrible code, just press 'back' now.

    Assignment where I have to use a header and .c file to implement an abstract data type for lists containing ints.

    Anywho, in the end, it's supposed to be able to do several things,
    but the first is reading a set of ints from standard input, and adding them to the linked list in correct order, using EOF to stop.

    The code I have so far is largely copied from my notes,
    but a few conventions used, such as '->' don't seem to work.
    Was it pseudo code, and if so, for what!

    Basically.. I'm completely lost and in a panic...


    list.c *I'm updating this when I make changes.. and there are many to be made!*
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include "list.h"
    #define SIZE (sizeof( struct _LIST_ ))
    
    int j, input;
    int* list, tmp;
    
    
    
     struct _LIST_ {
      int number;
      struct _LIST_ *next;
     };
    
     typedef struct _LIST_ *LIST;
    
    
    
    
    
    extern void print_stuff( int i )
    	{
    	printf("i is %d \n", i);
    	}
    
    
    extern void create_list ()
    	{
    	list = malloc( SIZE );
    	scanf ("d%", &input);
    	if ( input != EOF)
    		{
    		list -> next = NULL;
    		list -> number = input;
    		}
    	else
    		{
    	printf ("no input");
    		}
    	scanf ("d%", &input);
    	while ( input = !EOF )
    		{
    		tmp = malloc( SIZE );
    		tmp -> next = list;
    		tmp -> number = input;
    		list = tmp;
    		}
    	}
    
    extern void free_list (void* list)
    	{
    	                      
    	while (list != NULL) 
    		{
       		tmp = list;
       		list = list->next;
       		free( tmp );
    		}
    
    
    	}
    
    
    extern void reverse_list (void* list);
    	{
    	}
    
    
    
    
    extern void print_list( void* list );
    	{
    	int search( int key, LIST list )
    		 {
      		while ((list != NULL) && (list->number != key))
       		 printf (list);
    		list = list->next;
     		 return (list != NULL);
    		}
    	}
    
    
    
    extern void read_list( void* *plist );
    	{
    	}
    
    
    extern void append_lists (void *list1, void *list2)
    	{	
    	}
    main.c
    Code:
    #include <stdio.h>
    #include "list.h"
    
    int main (){
    
    printf("Main is working\n");
    print_stuff(2);
    create_list();
    }
    list.h
    Code:
    #ifndef _LIST_H_
    #define _LIST_H_
    
    
    extern void print_list( void* list );
    extern void read_list( void* *plist );
    extern void free_list( void* list );
    extern void create_list ();
    extern void reverse_list(void* list);
    extern void append_lists(void* list1, void* list2);
    
    
    
    extern void print_stuff( int i );
    
    #endif /* list.h */
    Last edited by mercuryfrost; 08-22-2009 at 03:53 PM. Reason: updated whilst working

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. single linked list to double linked list (help)
    By Countfog in forum C Programming
    Replies: 8
    Last Post: 04-29-2008, 08:04 PM
  2. Duplicating value of pointer to linked list
    By zephyrcat in forum C Programming
    Replies: 14
    Last Post: 01-22-2008, 03:19 PM
  3. How to use Linked List?
    By MKashlev in forum C++ Programming
    Replies: 4
    Last Post: 08-06-2002, 07:11 AM
  4. Searching a linked list for char
    By spentdome in forum C Programming
    Replies: 3
    Last Post: 05-22-2002, 11:11 AM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM