| | |
Reading link list in files..
![]() |
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 |
#include * adobe ansi api array asterisks binarysearch centimeter changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic execv feet fgets file fork frequency function getlasterror getlogicaldrivestrin givemetehcodez global grade graphics gtkgcurlcompiling gtkwinlinux hacking highest histogram include incrementoperators infiniteloop input interest kernel keyboard kilometer linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft mqqueue number odf opendocumentformat owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scanf segmentationfault sequential shape single socket socketprograming standard string systemcall threads turboc unix user voidmain() wab whythiscodecausesegmentationfault windows.h windowsapi






