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

  • SEARCH
  • Home
  • 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 9136211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:55:23+00:00 2026-06-17T08:55:23+00:00

Sorry for the last thread and not responding; I went to bed and forgot

  • 0

Sorry for the last thread and not responding; I went to bed and forgot to post the full code; though I am still sorry for not answering.

The problem rests in the function “bool readFile()” and will crash my program if used a 2nd time.

I do not know how to fix this crash and would appreciate help on editing my code.

Thanks.

#include "basic.h"
#include "file.h"
#include "initialize.h"
#include "macros.h"
#include "values.h"
#include <map>
#include <string>
#include <fstream>
#include <iostream>
#include <winbase.h>
#include <iomanip>
#include <locale>
#include <sstream>

#pragma region Global Variables

EXTERN_C IMAGE_DOS_HEADER __ImageBase;

static enum StringValue { evS1, evS2, evS3, evS4, evS5, evS6, evS7, evS8, evS9, evS10, evS11, evS12, evS13, evS14, evS15, evS16, evS17, evS18, evS19, evS20, evS21, evS22, evS23, evS24, evS25, evS26, evS27, evS28, evS29, evS30, evS31, evS32, evS33, evS34, evS35, evS36, evS37, evS38, evS39, evS40, evS41, evS42, evS43, evS44, evS45};

static std::map<std::string, StringValue> s_mapStringValues;

static char Input[_MAX_PATH];

string Line[4];

int Temporary;

#pragma endregion

string retrievePath()
{
    LPTSTR strDLLPath1 = new TCHAR[_MAX_PATH];
    ::GetModuleFileName((HINSTANCE)&__ImageBase, strDLLPath1, _MAX_PATH);
    string::size_type pos = string(strDLLPath1).find_last_of("\\/");
    std:: string strRet = string(strDLLPath1).substr(0, pos);
    return strRet;
}

void initializeKeys()
{
    s_mapStringValues["0"] = evS1;
    s_mapStringValues["1"] = evS2;
    s_mapStringValues["2"] = evS3;
    s_mapStringValues["3"] = evS4;
    s_mapStringValues["4"] = evS5;
    s_mapStringValues["5"] = evS6;
    s_mapStringValues["6"] = evS7;
    s_mapStringValues["7"] = evS8;
    s_mapStringValues["8"] = evS9;
    s_mapStringValues["9"] = evS10;

    s_mapStringValues["A"] = evS11;
    s_mapStringValues["B"] = evS12;
    s_mapStringValues["C"] = evS13;
    s_mapStringValues["D"] = evS14;
    s_mapStringValues["E"] = evS15;
    s_mapStringValues["F"] = evS16;
    s_mapStringValues["G"] = evS17;
    s_mapStringValues["H"] = evS18;
    s_mapStringValues["I"] = evS19;
    s_mapStringValues["J"] = evS20;

    s_mapStringValues["K"] = evS21;
    s_mapStringValues["L"] = evS22;
    s_mapStringValues["M"] = evS23;
    s_mapStringValues["N"] = evS24;
    s_mapStringValues["O"] = evS25;
    s_mapStringValues["P"] = evS26;
    s_mapStringValues["Q"] = evS27;
    s_mapStringValues["R"] = evS28;
    s_mapStringValues["S"] = evS29;
    s_mapStringValues["T"] = evS30;

    s_mapStringValues["U"] = evS31;
    s_mapStringValues["V"] = evS32;
    s_mapStringValues["W"] = evS33;
    s_mapStringValues["X"] = evS34;
    s_mapStringValues["Y"] = evS35;
    s_mapStringValues["Z"] = evS36;

    s_mapStringValues["SHIFT"] = evS37;
    s_mapStringValues["CTRL"] = evS38;
    s_mapStringValues["ALT"] = evS39;
    s_mapStringValues["PAGE UP"] = evS40;
    s_mapStringValues["PAGE DOWN"] = evS41;
    s_mapStringValues["END"] = evS42;
    s_mapStringValues["HOME"] = evS43;
    s_mapStringValues["INS"] = evS44;
    s_mapStringValues["DEL"] = evS45;
}

void mapKeys()
{
    switch(s_mapStringValues[Input])
    {
      case evS1:
          Temporary = 0x30;
        break;
      case evS2:
          Temporary = 0x31;
        break;
      case evS3:
          Temporary = 0x32;
        break;
      case evS4:
          Temporary = 0x33;
        break;
      case evS5:
          Temporary = 0x34;
        break;
      case evS6:
          Temporary = 0x35;
        break;
      case evS7:
          Temporary = 0x36;
        break;
      case evS8:
          Temporary = 0x37;
        break;
      case evS9:
          Temporary = 0x38;
        break;
      case evS10:
          Temporary = 0x39;
        break;
      case evS11:
          Temporary = 0x41;
        break;
      case evS12:
          Temporary = 0x42;
        break;
      case evS13:
          Temporary = 0x43;
        break;
      case evS14:
          Temporary = 0x44;
        break;
      case evS15:
          Temporary = 0x45;
        break;
      case evS16:
          Temporary = 0x46;
        break;
      case evS17:
          Temporary = 0x47;
        break;
      case evS18:
          Temporary = 0x48;
        break;
      case evS19:
          Temporary = 0x49;
        break;
      case evS20:
          Temporary = 0x4A;
        break;
      case evS21:
          Temporary = 0x4B;
        break;
      case evS22:
          Temporary = 0x4C;
        break;
      case evS23:
          Temporary = 0x4D;
        break;
      case evS24:
          Temporary = 0x4E;
        break;
      case evS25:
          Temporary = 0x4F;
        break;
      case evS26:
          Temporary = 0x50;
        break;
      case evS27:
          Temporary = 0x51;
        break;
      case evS28:
          Temporary = 0x52;
        break;
      case evS29:
          Temporary = 0x53;
        break;
      case evS30:
          Temporary = 0x54;
        break;
      case evS31:
          Temporary = 0x55;
        break;
      case evS32:
          Temporary = 0x56;
        break;
      case evS33:
          Temporary = 0x57;
        break;
      case evS34:
          Temporary = 0x58;
        break;
      case evS35:
          Temporary = 0x59;
        break;
      case evS36:
          Temporary = 0x5A;
        break;
      case evS37:
          Temporary = 0x10;
        break;
      case evS38:
          Temporary = 0x11;
        break;
      case evS39:
          Temporary = 0x12;
        break;
      case evS40:
          Temporary = 0x21;
        break;
      case evS41:
          Temporary = 0x22;
        break;
      case evS42:
          Temporary = 0x23;
        break;
      case evS43:
          Temporary = 0x24;
        break;
      case evS44:
          Temporary = 0x2D;
        break;
      case evS45:
          Temporary = 0x2E;
        break;
      default:
        break;
    }
}

bool readFile()
{
    int lineCounter = 0;

    string fileLine;

    string configurationLocation = retrievePath() + "\\configuration";

    ifstream configurationFile;

    configurationFile.open(configurationLocation + ".config");

    if (!configurationFile)
    {
        return false;
    }
    else
    {
        while (getline(configurationFile, fileLine))
        {
            Line[lineCounter] = fileLine;
            DebugPrintA(Line[lineCounter].c_str());
            lineCounter++;
        }
    }
    configurationFile.close();
    return true;
}

bool assignKeys()
{
    if (Line[0] != "attack:")
    {
        string Line0 = Line[0].substr(Line[0].find(':') + 1);

        int TempLine0 = Line0.size();

        for (int a = 0; a <= TempLine0; a++)
        {
            Input[a] = Line0[a];
        }

        mapKeys();

        keys[attackKey] = Temporary;
    }
    else
    {
        keys[attackKey] = NULL;
    }

    if (Line[1] != "range:")
    {
        string Line1 = Line[1].substr(Line[1].find(':') + 1);

        if (Line1 == "melee")
        {
            rangeX = 0;
            rangeY = 0;
        }
        else
        {
            rangeX = 30;
            rangeY = 0;
        }
    }
    else
    {
        rangeX = 0;
        rangeY = 0;
    }

    if (Line[2] != "health: ;")
    {
        string Line2Temp = Line[2];

        string Line2 = Line[2].substr(Line[2].find(':') + 1);

        int Index1 = Line2.find(';');

        if (Index1 > 0)
        {
            Line2 = Line2.substr(0, Index1);
            healthValue = atoi(Line2.c_str());
        }

        string Line22 = Line2Temp.substr(Line2Temp.find(';') + 1);

        int TempLine2 = Line22.size();

        for (int a = 0; a <= TempLine2; a++)
        {
            Input[a] = Line22[a];
        }

        mapKeys();

        keys[healthKey] = Temporary;
    }
    else
    {
        keys[healthKey] = NULL;
    }

    if (Line[3] != "mana: ;")
    {
        string Line3Temp = Line[3];

        string Line3 = Line[3].substr(Line[3].find(':') + 1);

        int Index2 = Line3.find(';');

        if (Index2 > 0)
        {
            Line3 = Line3.substr(0, Index2);
            manaValue = atoi(Line3.c_str());
        }

        string Line33 = Line3Temp.substr(Line3Temp.find(';') + 1);

        int TempLine3 = Line33.size();

        for (int a = 0; a <= TempLine3; a++)
        {
            Input[a] = Line33[a];
        }

        mapKeys();

        keys[manaKey] = Temporary;
    }
    else
    {
        keys[manaKey] = NULL;
    }

    if (Line[4] != "delay:")
    {
        string Line4 = Line[4].substr(Line[4].find(':') + 1);

        kamiDelay = atoi(Line4.c_str());
    }
    else
    {
        kamiDelay = 500;
    }

    if (keys[attackKey] != NULL && keys[healthKey] != NULL && keys[manaKey] != NULL)
    {
        Line[0].clear();
        Line[1].clear();
        Line[2].clear();
        Line[3].clear();
        Line[4].clear();
        return true;
    }
    else
    {
        Line[0].clear();
        Line[1].clear();
        Line[2].clear();
        Line[3].clear();
        Line[4].clear();
        return false;
    }
}
  • 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-17T08:55:24+00:00Added an answer on June 17, 2026 at 8:55 am

    In your assignKeys() function you access Line[4]. But the Line array only has 4 elements, so you can only access Line[0] to Line[3] safely. Accessing Line[4] might crash your program.

    Also if your configuration file has more than 4 lines, the statement Line[lineCounter] = fileLine; in readFile() will access elements of the Line array which are out of bounds. So you have to add some bounds checking to the while loop, too.

    The better alternative probably is to use std::vector<std::string>. Then you could simply push_back(...) the elements in the while loop in readFile(). In assignKeys() you would have to check the size of the vector before accessing any of it’s elements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry my last question was not well formated. So I am deleting the content
UPDATE: Sorry, forgot to include some of the code (face-palm). I included it in
sorry about the last question. (I hate google traductor). Im working in a MMO
First of all, sorry for my bad English. For my last project on my
Sorry for the bad title - I simply do not know what to call
Sorry but I am not sure how to ask this question but I am
Sorry, back agin How can I get at the last sortable item. I am
Sorry I can't be specific with code, but the problems I am seeing are
Sorry for the weird question. I'm new to web development (spent the last few
Sorry for being to vague last time I asked this question. I have this

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.