Thread: Linked List

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    39

    Linked List

    With the following code I keep getting the following errors:

    hw4.c: In function âread_numberâ:
    hw4.c:57: error: dereferencing pointer to incomplete type
    hw4.c:58: error: dereferencing pointer to incomplete type

    I've tried several different things to fix it but cannot figure it out. Linked lists are the only things I've had trouble with all year and I can never figure them out. Can someone please help me out with what is wrong with this code? Btw, all function prototypes cannot be changed.

    Code:
    typedef struct link_list list;
    
    struct list
    {
            int data;
            struct list *next;
    };
    
    list* read_number(char * str);
    list* create_node(int data);
    list* build_list(list * headptr, list *node);
    list* insert_node(list * headptr, int x);
    list* delete_node(list * headptr, int loc);
    void write_output(list * headptr, char * str);
    void print_list(list * headptr);
    
    FILE * in;
    FILE * out;
    
    int main(int argc, char **argv)
    {
    
            FILE * out;
            char * str;
            list * lst;
            int i;
    
            if(argc != 3)
            {
                    printf("Usage: <%s> <input file> <output file>\n", argv[0]);
                    return 0;
            }
            str = argv[1];
    
    
            lst = read_number(str)
    
            return 0;
    }
    
    list* read_number(char * str)
    {
            list *temp = malloc(sizeof(struct list));
            list *head = NULL;
            list *number;
            int num;
            in = fopen(str, "r");
            while(!feof(in))
            {
                    fscanf(in, "%d", &num);
                    temp->data = num;
                    temp->next = head;
    
            }
    
    
    
            return temp;
    }

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    there is no type list defined. it is struct list.
    and the typedef is the other way round and should be defined after the struct.
    Kurt

  3. #3
    Registered User
    Join Date
    Apr 2012
    Posts
    39
    Quote Originally Posted by ZuK View Post
    there is no type list defined. it is struct list.
    and the typedef is the other way round and should be defined after the struct.
    Kurt
    Thanks,
    That got it to compile, now hopefully I can get the rest

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Declaring linked list inside linked list
    By blueboyz in forum C Programming
    Replies: 33
    Last Post: 04-20-2012, 10:13 AM
  2. Replies: 4
    Last Post: 05-01-2010, 10:19 PM
  3. single linked list to double linked list (help)
    By Countfog in forum C Programming
    Replies: 8
    Last Post: 04-29-2008, 08:04 PM
  4. singly linked list to doubly linked list
    By t48j in forum C Programming
    Replies: 3
    Last Post: 03-23-2005, 06:37 PM
  5. Replies: 6
    Last Post: 03-02-2005, 02:45 AM