Hi, i know this has been asked a few times before, but even all the tutorials i have looked at and past threads can't make me understand.
Basically what i have got is a structure and a file which is created when a user 'logs in'. I am trying to read from this file directly into the structure, and then send it back again when the client quits to update any changed information. Here is what i have:
Code:
//The Structure
typedef struct
{
int level; //user level
int points; //user points
} client_aldarninfo_t;
//The logon function (ignore the fact it wont create the file if there isn't already one, also qboolean is valid)
qboolean client_login(edict_t *ent)
{
FILE *file;
if ((file = fopen(ent->client->pers.netname, "r")) == NULL) {
gi.cprintf (ent, PRINT_HIGH, "Error: can't open file.\n");
return 1;
}
else
{
int size = sizeof(client_aldarninfo_t);
//file opened, lets read it into the structure
fread(&ent->client->aldarn, size, 2, file);
gi.cprintf (ent, PRINT_HIGH, "Hey, your level is: %d, and your points are: %d\n", ent->client->aldarn.level, ent->client->aldarn.points);
return 0;
}
}
ent->client->pers.netname is the clients username.
Here is an example of what happens with "example.txt" having this contents:
Code:
Prints out: level: (big ASCII number), points: 49 (ASCII for 1)
Another example:
Code:
Prints out: level: (big ASCII number), points: 0
Basically, i have no idea how to assign the variables in the structure to exactly the numbers in the text file, seeing as i have no way of knowing the size of them before hand. Any help is appreciated, and feel free to e-mail/instant message. Thanx!!
- Aldarn