|
-
June 21st, 2004, 10:15 PM
#1
Can you spot the problem?
No, this isn't a gameshow. I have some code, and what it does is get some data from a TXT and fill it into a structure. Unfortunatly fscanf() isn't filling anything, and I'm afraid it has something to do with the current position. Here's code:
Code:
/* header */
typedef struct user
{
char *username;
char *password;
char *NAME;
int wins;
int lost;
int games;
int percentofwin;
int coins;
int track[16];
} user;
/* cpp */
#include "main.h"
...
int loadUserInfo()
{
int userCount;
int i;
userstxt = fopen("c:/users.txt", "r");
if(userstxt == NULL)
return -1;
fscanf(userstxt, "USRS %d", &userCount);
// Depending how long the number is, it will have a different seek.
if(userCount <= 9)
{
if(fseek(userstxt,8L,SEEK_SET)) return -1;
}
if(userCount > 9)
{
if(fseek(userstxt,9L,SEEK_SET)) return -1;
}
if(userCount > 99)
{
if(fseek(userstxt,10L,SEEK_SET)) return -1;
}
if(userCount > 999)
{
if(fseek(userstxt,11L,SEEK_SET)) return -1;
}
for(i = userCount; i != 0; i--)
{
fscanf(userstxt,"- %s PWD %s NAME %s WON %d LST %d GMS %d PNT %d CNS %d LC %d PB %d BP %d DD %d MB %d MC %d DC %d WS %d SL %d MC2 %d DK %d WC %d DJ %d BC %d RR %d",
&users[i].username,&users[i].password,&users[i].NAME,&users[i].wins,&users[i].lost,
&users[i].games,&users[i].percentofwin,&users[i].coins,&users[i].track[0],
&users[i].track[1],&users[i].track[2],&users[i].track[3],&users[i].track[4],
&users[i].track[5],&users[i].track[6],&users[i].track[7],&users[i].track[8],
&users[i].track[9],&users[i].track[10],&users[i].track[11],&users[i].track[12],
&users[i].track[13],&users[i].track[14],&users[i].track[15],&users[i].track[16]);
}
/* the txt */
USRS 1
- Dark Cube PWD whatever NAME Dark Cube WON 0 LST 0 GMS 0 PNT 0 CNS 250 LC 0 PB 0 BP 0 DD 0 MB 0 MC 0 DC 0 WS 0 SL 0 MC2 0 DK 0 WC 0 DJ 0 BC 0 RR 0
fscanf doesn't fill the structure with anything. I am puzzled.
Need help with anything related to audio programming? I can help!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|