Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.6 kB
2
Indexable
Never
void createCharacter(char playername[NAME_SIZE], char sirename[NAME_SIZE]) {

    FILE* userfile;
    FILE* clanes;
    FILE* sires;

    Sire s;
    Character c;
    Clan cl;

    char name[NAME_SIZE];
    
    strcpy ( name, playername );
    
    strcat ( name, ".bin" );

    printf("%s", name);

    sires = fopen("sires.bin", "rb");
    if(NULL == sires) {
        //bad
    } else {
        //good
        printf("Sires file opened successfully\n");
        fread(&s, sizeof(Sire), 1, sires);
        while(!feof(sires)) {
            if(strcmp(sirename, s.name) == 0) {
                strcpy(c.sire_name, s.name);
                strcpy(c.clan_name, s.clan_name);
                c.generation = s.generation+1;
            }
            fread(&s, sizeof(Sire), 1, sires);
        }

        fclose(sires);
    }

    clanes = fopen("clans.bin", "rb");
    
    if(NULL == clanes) {
        //bad
    } else {
        //good
        fread(&cl, sizeof(Clan), 1, clanes);
        while(!feof(clanes)) {
            if(strcmp(c.clan_name, cl.name) == 0) {

                strcpy(c.disciplines[0], cl.disciplines[0]);
                strcpy(c.disciplines[1], cl.disciplines[1]);
                strcpy(c.disciplines[2], cl.disciplines[2]);
                strcpy(c.bane, cl.bane);
            }
            fread(&cl, sizeof(Clan), 1, clanes);
        }

        fclose(clanes);

    }


    userfile = fopen(name, "wb");
    if(NULL == userfile) {
        //bad
    } else {
        //good
        fwrite(&c, sizeof(Character), 1, userfile);
        fclose(userfile);
    }
    




}