Help with linked list

This is a discussion on Help with linked list within the C Programming forums, part of the General Programming Boards category; Oh man, pointer to pointer?? Is this only possible with pointer to pointer definition?...

  1. #16
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Oh man, pointer to pointer?? Is this only possible with pointer to pointer definition?
    Last edited by GaPe; 02-08-2002 at 03:26 AM.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  2. #17
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    You don't have to use a pointer to pointer, but if you don't use one than you have to use a return type for example:

    //prototype
    List * Function(List *);

    List *ptr_to_List_complex_type;

    ptr_to_List_complex_type = Function(ptr_to_List_complex_type);


    Whereas a pointer to pointer is cleaner:

    void Functon(List **)
    List *ptr_to_List_complex_type;

    Function(&ptr_to_List_complet_type);

    In both cases the List up updated in main.

  3. #18
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Ok, just a moment. Are you playing with me?? At first you write "void ReadList (List *, char *)" and then you write in a "OpenFunction" "start = ReadList(fin,start);". This is totally wrong.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  4. #19
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    For me it's cleaner the return type. I understand it better .
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  5. #20
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    I edited it because I'm writing very quickly and I cut and paste while some of it still has not been updated. Sorry about that. I'm working on it right now I'll show you the changes I've made. The biggest change is to take the control out of your ReadList function and place part of it in main. You had too many things going on in your ReadList function. The file pointer should be passed into the function rather than opening the file in that function and building the list. I'll show you in a few minutes.

  6. #21
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Does the file just contain integers?

  7. #22
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    yes.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  8. #23
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    First number is 0, second is 10. LOL, Okay give me a few more minutes. I've been working with character files for a long time. Just need to sort out a few things.

  9. #24
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    hmm,

    0
    10
    6
    1
    0
    -842150451

    Are these correct conversion for the binary file or is the last number not correct? I have not used binaries for some time.

  10. #25
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    When I print out these numbers I get 0, 10, 6, 1, 0.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  11. #26
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Okay I'll work on it and post when I get the answer. I'm having trouble picking up eof with fread. I have not used binaries for a looong time.

  12. #27
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    I now have put the numbers into a linked list but I am still having trouble with NULL! Just need to fiure that out.

  13. #28
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    It might be that you have to know the size of your datafile, that is how many records it holds. If I know how many records it holds than I have no problem. The problem occurs when it reads feof. The last record is causing the error. With textfiles I know the work around but I'm stumped with the binary file. I know of one work around, that would be to write the file first and get the count for the number of records. One you have the count than fread is not a problem and building a linked list is not a problem.

  14. #29
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    That feof is a pain in the ass, I know.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  15. #30
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Okay I figured it out. In a short while I'll post what I'm talking about! I have the solution. FINALLY I might add.

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Linked list program need help !!!
    By dcoll025 in forum C++ Programming
    Replies: 1
    Last Post: 04-20-2009, 11:03 AM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 11:10 AM
  3. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 11:01 AM
  4. Template Class for Linked List
    By pecymanski in forum C++ Programming
    Replies: 2
    Last Post: 12-04-2001, 09:07 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 11:21 PM

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