0

I have the following structs:

typedef struct PList {
    struct PList* next;
    Person value;
} PList;

typedef struct Person{
        char name[100]; // Left as "" if empty Person
        PersonID ID;
        float amountOwed;
}Person;

typedef struct PersonID{
        char letter;
        int number; // 7 digits
}PersonID;

Before i leave the program everything is stored correctly, however after leaving(hence saving), then reopening (hence loading), the Person.ID.number becomes 0

Here are saving and loading portions (customers is a PList):

SAVING

file = fopen("SaveData/customers.dat", "w");
int a;
    a = lengthPList(&customers);
    fwrite(&a, sizeof(int), 1, file);
    PList* temp;
    temp = &customers;
    for (; a > 0; a--) {
        int b;
        b = sizeof(temp->value);
        fwrite(&b, sizeof(int), 1, file);
        fwrite(&temp->value, sizeof(temp->value), 1, file);
        if (a > 1)
            temp = temp->next;
    }

LOADING

file = fopen(fileName, "r");
int a;
            fread(&a, sizeof(int), 1, file);
            for (; a > 0; a--) {
                Person a;
                int b;
                fread(&b, sizeof(int), 1, file);
                fread(&a, b, 1, file);
                addPersonToList(&a, &customers);
            }

OLD CODE

Saving

file = fopen(fileName, "w");
int a;
a = lengthPList(&customers);
fwrite(&a, sizeof(int), 1, file);
fwrite(&customers, sizeof(customers), a, file);

Loading

file = fopen(fileName, "r");
int a;
fread(&a, sizeof(int), 1, file);
fread(&customers, sizeof(customers), a, file);
mangusbrother
  • 3,988
  • 11
  • 51
  • 103

0 Answers0