FILE IO Error

Non-platform specific questions.

FILE IO Error

Postby EvanBlack » Sat Oct 22, 2011 4:40 am

Error line 16 Incompatible Types: Cannot convert from 'double' to ' * const char '

Code: Select all
typedef struct NewStruct
{
    int a;
    int b;
    char c[20];
} NewStruct;

NewStruct myStruct;
FILE *g_DATAMAPFILE;

NewStruct * pMyStruct = &myStruct;


int SaveDataMap()
{
    g_DATAMAPFILE = fopen("Level.txt", r+b); //fopen error
    if(g_DATAMAPFILE == NULL) {return 1;}
    fwrite(pMyStruct, sizeof(*pMyStruct), 1, g_DATAMAPFILE);
    fclose(g_DATAMAPFILE);
    return 0;
   
}

void init()
{
    pMyStruct->a = 20;
    pMyStruct->b = 55;
    strcpy(pMyStruct->c, "String");
    if(!SaveDataMap()){ExitGame();}
}
(\__/) ( Soon... The world)
(O.o )< will be mine!____)
(> < )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bunny Overlord 2012!
EvanBlack
 
Posts: 202
Joined: Fri Sep 30, 2011 10:17 am
Score: 19 Give a positive score

Re: FILE IO Error

Postby skydereign » Sat Oct 22, 2011 5:05 am

You need the format to be a const char*. "r+b", not r+b.
Code: Select all
typedef struct NewStruct
{
    int a;
    int b;
    char c[20];
} NewStruct;

NewStruct myStruct;
FILE *g_DATAMAPFILE;

NewStruct * pMyStruct = &myStruct;


int SaveDataMap()
{
    g_DATAMAPFILE = fopen("Level.txt", "r+b"); // fopen error fixed
    if(g_DATAMAPFILE == NULL) {return 1;}
    fwrite(pMyStruct, sizeof(*pMyStruct), 1, g_DATAMAPFILE);
    fclose(g_DATAMAPFILE);
    return 0;
   
}

void init()
{
    pMyStruct->a = 20;
    pMyStruct->b = 55;
    strcpy(pMyStruct->c, "String");
    if(!SaveDataMap()){ExitGame();}
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: FILE IO Error

Postby EvanBlack » Sat Oct 22, 2011 5:49 am

Oh thanks! I was trying to figure out why it said i couldnt use w lol thanks! I must have over looked it.
(\__/) ( Soon... The world)
(O.o )< will be mine!____)
(> < )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bunny Overlord 2012!
EvanBlack
 
Posts: 202
Joined: Fri Sep 30, 2011 10:17 am
Score: 19 Give a positive score

Re: FILE IO Error

Postby EvanBlack » Mon Oct 24, 2011 5:33 am

Having trouble figuring out how to save and load from an array of structs... Here is my code.

I changed it a couple of times to try different things and nothing worked. Here is the last thing I tried.


BINSAVE.ged Script:
Code: Select all
typedef struct NewStruct
{
    int a;
    int b;
    char c[20];
} NewStruct;

NewStruct myStruct;
NewStruct myStruct2;
FILE *g_DATAMAPFILE;
NewStruct * pMyStruct[2];


int SaveDataMap()
{
    g_DATAMAPFILE = fopen("Level.txt", "wb");
    if(g_DATAMAPFILE == NULL) {return 1;}
    fwrite(pMyStruct, sizeof(NewStruct)*2, 1, g_DATAMAPFILE);
    fclose(g_DATAMAPFILE);
    return 0;
 
}

void init()
{
    pMyStruct[0] = &myStruct;
    pMyStruct[1] = &myStruct2;
 
    pMyStruct[0]->a = 20;
    pMyStruct[0]->b = 55;
    strcpy(pMyStruct[0]->c, "String");
 
    pMyStruct[1]->a = 99999;
    pMyStruct[1]->b = 77777;
    strcpy(pMyStruct[1]->c, "LOLFUCKLMAO");
 
    if(!SaveDataMap()){ExitGame();}
}




BINLOAD.ged Script:
Code: Select all

typedef struct NewStruct
{
    int a;
    int b;
    char c[20];
} NewStruct;

NewStruct myStruct;
NewStruct myStruct2;
FILE *g_DATAMAPFILE;
NewStruct * pMyStruct[2];


int LoadDataMap()
{
    g_DATAMAPFILE = fopen("Level.txt", "rb");
    if(g_DATAMAPFILE == NULL) {return 1;}
    fread(pMyStruct, sizeof(*pMyStruct[0]) * 2, 2, g_DATAMAPFILE);
    fclose(g_DATAMAPFILE);
    return 0;
 
}

void init()
{
    pMyStruct[0] = &myStruct;
    pMyStruct[1] = &myStruct2;
    if(LoadDataMap())
    {
        ExitGame();
    }
}



Edit: I got it to work using a for loop, but how do I do it without a loop?
(\__/) ( Soon... The world)
(O.o )< will be mine!____)
(> < )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bunny Overlord 2012!
EvanBlack
 
Posts: 202
Joined: Fri Sep 30, 2011 10:17 am
Score: 19 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest