Hello.
I'm programming a program to make a mp4 player.
After finishing the program I need to add and option to save the linked list for using it later. I've succeeded to save all the content of the list to a txt file, but fail to get it back to the list.
linkedList.h:
Code:
#ifndef LINKEDLISTH
#define LINKEDLISTH
#include "Frame.h"
struct Link
{
frame_t *frame;
struct Link *next;
struct Link *prevoius;
};
typedef struct Link link_t;
#endif
Frame.h
Code:
ifndef FRAME_H
#define FRAME_H
#include <stdio.h>
struct Frame
{
char *name;
unsigned int duration;
char *path; // may change to FILE*
};
typedef struct Frame frame_t;
#define MAX_PATH_SIZE (256)
#define MAX_NAME_SIZE (50)
#endif //FRAME_H
linkedList.c
Code:
int writeListTo,File(const link_t *list);
int readListFromFile(const link_t *list);
int readListFromFile(const link_t *list){
FILE *pfile = fopen("s.txt", "r");
fseek(pfile, SEEK_SET, 0);
if (pfile != NULL) {
while (!feof(pfile)) {
fscanf(pfile, "%s %s %d", &list->frame->name, &list->frame->path, &list->frame->duration);
}
fclose(pfile);
return 1;
}
else{
printf("Error opening file");
fclose(pfile);
}
}
int writeListToFile(const link_t *list) {
int c = 0;
FILE *pfile = fopen("SavedList.txt", "w");
if (pfile != NULL) {
for (; list != NULL; list = list->next) {
fprintf(pfile, "%s %s %d ", list->frame->name, list->frame->path, list->frame->duration);
}
}
fclose(pfile);
return 1;
}
What am I doing wrong?