It will never work. You read only the value of the pointer argv
but not the referenced array of pointers and strings assigned to it. Even if you read it they will reference other memory areas than the original ones when written.
You will need to serialize it and save all the underlying data. Then you will need to read it and reconstruct the structure.
example:
typedef struct
{
unsigned id;
unsigned timing;
//command *command;
unsigned argc;
char ** argv;
} taskR;
char *removeLastLF(char *str)
{
char *wrk = str;
if(str && str)
{
while(*(str + 1)) str++;
if(*str == '\n') *str = 0;
}
return wrk;
}
int mywrite(FILE *fo, taskR *t)
{
fprintf(fo, "%u,%u,%u\n", t -> id, t -> timing, t -> argc);
for(unsigned i = 0; i < t -> argc; i ++)
{
fprintf(fo, "%s\n", t -> argv[i]);
}
return 0;
}
taskR *myread(FILE *fi)
{
char buff[128];
taskR *t = malloc(sizeof(*t));
if(t)
{
fgets(buff, 128, fi);
if(sscanf(buff, "%u,%u,%u\n", &t -> id, &t -> timing, &t -> argc) == 3)
{
t -> argv = malloc(t -> argc * sizeof(*t -> argv));
for(unsigned i = 0; i < t -> argc; i ++)
{
fgets(buff, 128, fi);
removeLastLF(buff);
t -> argv[i] = malloc(sizeof(**t -> argv) * strlen(buff) + 1);
strcpy(t -> argv[i], buff);
}
}
}
return t;
}
It requires much more error checking but I have skipped it for the sake of simplicity.