Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8164005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:12:24+00:00 2026-06-06T19:12:24+00:00

I created a function which loads a very basic map file of the form:

  • 0

I created a function which loads a very basic map file of the form:

1:1 2:1 1:1 2:2 2:2 2:2 ...
................... 2:1 1:1

However, when using fscanf to read in the file, I am getting some very odd behaviour.

Looking at the FILE variable I have set up to read the map, the base element of the ‘stream’ of the FILE seems to have read the file perfectly. However, the _ptr of the ‘stream’ of the FILE is missing the first number, and the last. So it gets read as:

:1 2:1 1:1 2:2 2:2 2:2 ...
................... 2:1 1:

and is generating an error.

Here is my function:

/**
 *  loads a map
 */
bool Map::LoadMap(char* tFile)
{
    FILE* FileHandle = fopen(tFile, "r");           // opens map file for reading

    if (FileHandle == NULL)                         // returns if the map file does not exist
        return false;

    for(int Y = 0; Y < MAP_HEIGHT; Y++)             // iterates through each row
    {
        for(int X = 0; X < MAP_WIDTH; X++)          // iterates through each column
        {
            Node    tNode;                          // temp node to put in the map matrix

            int     tTypeID     = 0;
            int     tNodeCost   = 0;

            fscanf(FileHandle, "%d:%d", tTypeID, tNodeCost);

            tNode.SetPosition(X, Y);
            tNode.SetType(tTypeID);
            tNode.SetNodeCost(tNodeCost);

            mMap[X][Y]      = tNode;                // inserts temp node into list
        }
        fscanf(FileHandle, "\n");
    }

    fclose(FileHandle);

    return true;
}

Why this is happening?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:12:25+00:00Added an answer on June 6, 2026 at 7:12 pm

    You need to pass the addresses of the variables to fscanf():

    fscanf(FileHandle, "%d:%d", &tTypeID, &tNodeCost);
    

    Recommend checking the return value of fscanf() to ensure success:

    // fscanf() returns the number of assignments made or EOF.
    if (2 == fscanf(FileHandle, "%d:%d", &tTypeID, &tNodeCost))
    {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using xlwDotNet, I have created a simple function which returns one number. Sometimes, something
I created a header file called ofdm.h which includes all the function prototypes. Then
Ive created a function which returns all the obserables items in my html page.
I have created a function which gets an encoded string (possibly UTF-16 not sure)
I have created an utility function which I include in almost all Javascript code
I have created a JS function which executes fine when it's included an the
I have created a add input field function which is working fine. I would
I created webservice which contain Add function as 'webmethod' when we want to deploy
I created a sample webservice which contain default 'HelloWorld' function as 'webmethod' when tried
I have created a class extending SimpleXMLElement which loads an XML containing translations for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.