![]() |
| ||
| File problem in link list hello.. its me again and Im having problems with files again..this time, its with link list.. I can't get my program to display the contents it reads from a file. Please help.. I want to solve this myself but I have no time, my exam will start in 1 hour..:( void save_file(LIST L) |
| ||
| Re: File problem in link list I hope your implementation of list is something like : typedef struct node * LIST; In the save_file function: Quote:
struct node{And after all the proper memory assignments for the node and the character array you should use it as:for(p = L; p != NULL; p=p->next) And the statements LIST *Aand p=*A;are absolute nonsence because if p is of type node* then p=A is enough and if p is of type node then p=*A becomes meaningless. And if you have implemented the list as something like: typedef struct node LIST;Then the statements p=p->link;loose value. Its kind of an confusion with your program. |
| ||
| Re: File problem in link list Exactly as csurfer said. You're trying to traverse your linked list but you're also overwriting each node from the file read thus invalidating your pointer! Exit your functions upon errors. Don't keep trying to load or save data when you have no file handle! |
| ||
| Re: File problem in link list sob.. its still not working.. here's my main function and structure: typedef struct |
| ||
| Re: File problem in link list How many records in a data file? for(p = *A; p != NULL; p = p->next)You have to test the eof(). Can fread() allocate a node? ? |
| ||
| Re: File problem in link list Hey you want us to do all the work ??? ;) Try on your own man...Put in some effort...Go on reading each line like a compiler does and ya if you are using Boreland C then may be F7 will help you trace program flow line by line.So try to debug it. Some of the errors which you can easily find : 1>No semicolon after the struct cell. 2>You have declared A and L as LIST A,L;and LIST is itself struct node * type how can you pass pointer to this pointer...? As in p = *A; @adatapost : Let him correct these primitive mistakes first adatapost memory allocation and other things are off limits if he cannot trace these simple mistakes.Basically he is not putting in the effort required!!! |
| All times are GMT -4. The time now is 10:21 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC