-
July 29th, 2013, 09:30 PM
#1
Assigning a value to struct variables?
Hi guys, I'm trying to assign a value to the variables in my struct using the statement:
fscanf(fp, "%s%10s%9s%s", acct.name, acct.num, acct.pin, strbal)
but when I try to access them, it looks like the variables (acct.name, acct.num, acct.pin) are all empty. Also, can someone point me to a good reference material (that is not too hard to understand, if you know what I mean) that has basic examples? Thanks.
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAXAMT 999999.99
typedef struct Account{
char name[60];
char num[20];
char pin[10];
float bal;
} Account;
Account acct;
...
void loadAcct(){
char strbal[20];
FILE *fp;
fp = fopen("/acctinfo.txt", "r+");
if (fp != NULL) {
while(4 == fscanf(fp, "%s%10s%9s%s", acct.name, acct.num, acct.pin, strbal)) {
acct.bal = atof(strbal);
printf("%s\n%s\n%s\n%f\n", acct.name, acct.num, acct.pin, acct.bal);
}
} else {
printf("Account info not found.");
}
fclose(fp);
getch();
}
Last edited by riechan; July 30th, 2013 at 03:22 AM.
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
|