CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 29

Threaded View

  1. #1
    Join Date
    Jul 2013

    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.

    #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.");
    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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.