0

im making gif maker using opencv and linked lists

now the structure is

// Frame struct
typedef struct Frame
{
    char* name;
    unsigned int    duration;
    char* path;
} Frame;


// Link (node) struct
typedef struct FrameNode
{
    Frame* frame;
    struct FrameNode* next;
} FrameNode;

the frameNode contains a frame that has all the data and it has next that is used for the linked list

now i want to save the data after making a gif let's say i have 3 frameNodes in the list

Name            Duration                Path
1               200 ms            C:\Users\magshimim\Desktop\test\tt.png
2               500 ms
C:\Users\magshimim\Desktop\test\t.jpg
3               800 ms                  C:\Users\magshimim\Desktop\test\kitten_run.jpg

how do i save the name, duration, path and the next of each frameNode that when i comeback later on i can load the file and continue from where i left?

  • 1. Define the file format to use. 2. Implement load and save function for the file format. – MikeCAT May 31 '21 at 13:56
  • You never save pointer values in a file. For this case just save name, duration, path – Support Ukraine May 31 '21 at 13:59
  • then how could i load the list in the right order and, i heard about json file format but idk if it suits what i want to do and if possible to give some tips and directions on how to make that – Hillskiller May 31 '21 at 14:00
  • You can use `fprintf` - see https://man7.org/linux/man-pages/man3/fprintf.3p.html – Support Ukraine May 31 '21 at 14:00
  • 1
    @Hillskiller The order of data in the file shall be the same as the order in the list. So you kind of get the order "for free" – Support Ukraine May 31 '21 at 14:02
  • like i'm trying to think of a way to save that efficently without much work on loading, i could just save everything path,duraion,name.... but idk how to actually parse the data from the file like which data belongs to which frame... – Hillskiller May 31 '21 at 14:02
  • Write one line per frame - like `fprintf("%s %d %s\n", name, duration, path);` – Support Ukraine May 31 '21 at 14:03
  • or write them on 3 individual lines – Support Ukraine May 31 '21 at 14:04
  • if their in one line let's say imageOne 200 C:\desktop how could i parse each individual thing by itself like how could i get the values like that? – Hillskiller May 31 '21 at 14:05
  • Checck `fgets` and `sscanf` – Support Ukraine May 31 '21 at 14:07
  • alright so i made a function that saves output – Hillskiller May 31 '21 at 14:30
  • it saves them as the following https://pastebin.com/raw/bKrCAS8X now the question is how do i load them back? @4386427 – Hillskiller May 31 '21 at 14:31
  • As I wrote above. Check `fscanf` or better: `fgets` and `sscanf`. – Support Ukraine May 31 '21 at 14:40
  • Use a text file, write a frame (3 items) per line. The string shall be written between double quotes (escape double quotes if they are possible in the string) and separate each by a semicolon. A line looks like *"1";200;"C:\Users\magshimim\Desktop\test\tt.png"*. To reload, you'll have to parse each line character by character. – fpiette May 31 '21 at 15:06
  • could you help me in making the function for reloading because ik about looping over each character in loop but not sure how to split ";\n – Hillskiller May 31 '21 at 15:14
  • [Overlapping questions](https://stackoverflow.com/questions/67777103/parsing-data-from-file-into-linked-list-in-c). – Oka May 31 '21 at 16:15

0 Answers0