Page 3 of 3 FirstFirst 123
Results 21 to 24 of 24

Thread: Writing to file using fwrite?

  1. #21
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,279
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Writing to file using fwrite?

    You are using a single variable gold to try to hold two different values at the same time.
    1. The integer value scanned ( &gold )
    2. The number of items read by fscanf ( gold = fscanf(...); )

    Use two different variables for the two different purposes.

  2. #22
    Join Date
    Mar 2008
    Location
    Ireland
    Beans
    808
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Writing to file using fwrite?

    Right so we have a value to hold the fscanf value called readGold. Then I have gold which im gonna set to the actual value. However it seems to end up with a crazy high number now. Probably setting the gold to the address of it rather than the value.

    Code:
    int readGold = fscanf(READ, "%d [^\n]", &gold);
       if(readGold == 1)
       {
         gold = 0;
         gold = (READ, "%d", &gold);
         break;
       }
    Am I at least on the right track here? ..or have I lost my way? :S
    Projects: PhotoFiltre LX | Xwii | URT-2D | TTM

  3. #23
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,270
    Distro
    Kubuntu

    Re: Writing to file using fwrite?

    Why make things so difficult? Keep it simple:
    Code:
    int gold;
    
    if (fscanf(READ, "%d [^\n]", &gold) != 1)
    {
        // error
    }

  4. #24
    Join Date
    Mar 2008
    Location
    Ireland
    Beans
    808
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Writing to file using fwrite?

    My code works in a normal .c file but not inside GameEditor, so it much be a bug with that.

    Sorry for the confusion folks! :/
    Projects: PhotoFiltre LX | Xwii | URT-2D | TTM

Page 3 of 3 FirstFirst 123

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •