Linked List

This is a discussion on Linked List within the C Programming forums, part of the General Programming Boards category; With the following code I keep getting the following errors: hw4.c: In function Ôread_numberÔ: hw4.c:57: error: dereferencing pointer to incomplete ...

  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
    ZuK
    ZuK is online now
    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, 05:37 PM
  5. Replies: 6
    Last Post: 03-02-2005, 01:45 AM

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