Here's a better example:
PHP Code:
struct datafile {
char *str1;
char *str2;
int number;
linkedlist *list;
}
write_datafile(struct *datafile, char *filename)
{
FILE *fp = fopen(filename, "w");
fprintf(fp, "str1 %s\n", datafile->str1);
fprintf(fp, "str2 %s\n", datafile->str2);
fprintf(fp, "number %d\n", datafile->number);
linkedlist *iter = datafile->list;
while (iter) {
fprintf(fp, "item = %s", iter->data);
iter = iter->next;
}
}
The format of the file will be the name of the field, any amount of whitespace chars, and then everything from the first non-whitespace char to the end of the line is the value.
An example file for the above program:
Code:
str1 a string
str2 another longer string
item these
item are
item list
number 32
item items