| | |
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 api array arrays asterisks binarysearch calculate char cm copyanyfile copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic feet fflush fgets file fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o include incrementoperators input interest kernel kilometer linked linkedlist linux linuxsegmentationfault list lists locate logical_drives loopinsideloop. match matrix meter microsoft motherboard mqqueue mysql number odf open opensource owf pattern pdf performance pointer posix probleminc process program programming pyramidusingturboccodes radix read recursion recv repetition research scanf scheduling scripting segmentationfault send sequential shape socket socketprograming stack standard string systemcall turboc unix user voidmain() wab win32api windows.h






