Databse Struct generator

Game Editor comments and discussion.

Databse Struct generator

Postby Hblade » Wed Jan 16, 2013 12:48 am

I'm going to be developing a code generator. It will generate a number of database structs with an example code as follows:
Code: Select all
#define u_month DATA[0]
#define u_day DATA[1]
#define u_year DATA[2]

struct UserData {
    int DATA[3];
    char *firstName;
    char *middleName;
    char *lastName;
};
struct UserData Database1;

void
saveUserData(char *fileName)
{
    FILE *file=fopen(fileName, "w");
 
    if(file!=NULL)
    {
        fprintf(file, "Month: %d\n", Database1.u_month);
        fprintf(file, "Day: %d\n", Database1.u_day);
        fprintf(file, "Year: %d\n", Database1.u_year);
        fprintf(file, "First Name: %s\n", Database1.firstName);
        fprintf(file, "Middle Name: %s\n", Database1.middleName);
        fprintf(file, "Last Name: %s\n", Database1.lastName);
        fclose(file);
    }
}

void
loadUserData(char *fileName)
{
    FILE *file=fopen(fileName, "r");

    if(file!=NULL)
    {
        fscanf(file, "Month: %d\n", &Database1.u_month);
        fscanf(file, "Day: %d\n", &Database1.u_day);
        fscanf(file, "Year: %d\n", &Database1.u_year);
        fscanf(file, "First Name: %s\n", &Database1.firstName);
        fscanf(file, "Middle Name: %s\n", &Database1.middleName);
        fscanf(file, "Last Name: %s\n", &Database1.lastName);
        fclose(file);
    }
}


As you can see, it will also generate a file save and file load function. The file will save to a .c file which you can then import it to your project



This is useful for people create a game/software that stores user information for multiple users
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Databse Struct generator

Postby RippeR7420 » Fri Jan 18, 2013 5:42 pm

Sounds awesome :)
CURRENT PROJECTS:

-Olo: The Sword Shaman http://game-editor.com/forum/viewtopic.php?f=4&t=12919

-The Wrath of Blob: (On the back burner)

-StickMcGee - Blast to the Future http://game-editor.com/forum/viewtopic.php?f=4&t=13660
User avatar
RippeR7420
 
Posts: 391
Joined: Mon Apr 27, 2009 4:16 pm
Location: Salt Lake City, Utah.
Score: 23 Give a positive score

Re: Databse Struct generator

Postby Hblade » Fri Jan 18, 2013 10:22 pm

This is actually made already in advanced topics
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Databse Struct generator

Postby GEuser » Sat Jan 19, 2013 12:16 am

Unfortunately structs don't work for me so have laid off them :(
GEuser
 
Posts: 204
Joined: Thu Jan 05, 2012 3:08 pm
Score: 19 Give a positive score

Re: Databse Struct generator

Postby Hblade » Sat Jan 19, 2013 5:09 am

just use the generator :) In advanced topics it creates them without error
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest