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)
{
FILE *fp;
char filename[30];
LIST p;
printf("What is the name of the file? ");
flushall();
gets(filename);
if((fp = fopen(filename, "wb")) == NULL)
{
printf("Cannot write file");
}
for(p = L; p != NULL; p=p->next)
fwrite(&p, sizeof(celltype), 1, fp);
printf("File Saved");
fclose(fp);
getch();
clrscr();
}
void load_file(LIST *A)
{
FILE *fp;
char filename[30];
size_t c;
LIST p, temp;
printf("What is the filename? ");
flushall();
gets(filename);
if((fp = fopen(filename, "rb")) ==NULL)
{
printf("File does not exist");
}
for(p = *A; p != NULL; p = p->next)
{
fread(&p, sizeof(celltype), 1, fp);
}
printf("File Loaded");
getch();
clrscr();
}