| | |
Reading link list in files..
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Hello.. How can I read a link list from a file without reading a garbage node? I don't know much about how file works..
This is my code fragment:
please help
This is my code fragment:
c Syntax (Toggle Plain Text)
for(p = A; flag != 1;) { *p = (LIST) malloc(sizeof(celltype)); if((fread(*p, sizeof(celltype), 1, fp)) == 0) flag = 1; p = &(*p)->next; } *p = NULL;
C Syntax (Toggle Plain Text)
LIST *list = NULL; while ( fread( &temp, sizeof temp, 1, fp ) == 1 ) { LIST *node = makeNewNode( &temp ); // allocate and copy list = append( list, node ); // append }
If the file is empty, then the list at the end is NULL (an empty list).
•
•
•
•
Where is the junk node?C Syntax (Toggle Plain Text)
LIST *list = NULL; while ( fread( &temp, sizeof temp, 1, fp ) == 1 ) { LIST *node = makeNewNode( &temp ); // allocate and copy list = append( list, node ); // append }
If the file is empty, then the list at the end is NULL (an empty list).
this is my "wright" code fragment:
c Syntax (Toggle Plain Text)
for(p = L; p != NULL; p=p->next) fwrite(p, sizeof(celltype), 1, fp);
So if your concern is just the last but one node that is if you say that the node whose node->link is your junk node and you don't want to read it then you can just do this :
So that you stop writing just before the last node.
c Syntax (Toggle Plain Text)
for(p = L; p->next != NULL; p=p->next)
Last edited by csurfer; Jul 5th, 2009 at 12:04 am.
I Surf in "C"....
![]() |
Similar Threads
- reading/writing text files question - HELP! (Python)
- Help me please with reading in linked list txt file (C++)
- Link List Insert problems (C++)
- how to reverse link list using recurtion (C)
- Using a class to add/delete/show numbers in a Link List (C++)
- circular link list (C)
Other Threads in the C Forum
- Previous Thread: Program Keeps reading wrong input
- Next Thread: The C Programming Language
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays asterisks binarysearch calculate centimeter char command convert copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax directory drawing dynamic executable fflush file fork forloop frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix problem probleminc program programming radix recursion recv repetition research scanf scheduling scripting segmentationfault send sequential shape socketprograming spoonfeeding stack standard string strings structures student systemcall testautomation turboc unix user variable voidmain() wab windows.h






