Exception thrown at 0x0FE7DB1B (ucrtbased.dll) in PhysDesignAssignment1.exe: 0xC0000005: Access violation reading location 0xFDFDFDED

0

I was curious why my code throws the following exception Exception thrown at 0x0FE7DB1B (ucrtbased.dll) in file.exe: 0xC0000005: Access violation reading location 0xFDFDFDED.

My ultimate goal here is to create a 2d array with number of row indices as there is lines of text minus 6.

I also want to store the substring r into a string array of the same amount of indices as there is in myNodes.

#include <iostream>
#include <fstream>
#include "file.h"
#include <string>
#include <map>

using namespace std;

int main() {
    int index = -1;
    int** myNodes = new int*;
    //char* nameNodes;
    string line;
    ifstream myfile("spp_N151_E192_R8_232.nodes.txt");
    if (myfile.is_open())
    {
        while (myfile.good())
        {
            index += 1;
            getline(myfile, line);
            //genNode(&myNodes, index);
            string r = line.substr(0, 200);
            //nameNodes[index] = new string;
            //nameNodes[index] = r;
            //cout << "String is: " << r << endl;
        }
        myfile.close();
        for (int i = 0; i < (index - 6); i++) {
            myNodes[i] = new int[5];
            genNode(&myNodes, i);
            cout << "myNodes [" << i << "]" << myNodes[i] << endl;
        }
        cout << "Number of nodes: " << index << endl;
    }
    else cout << "Unable to open file";

    //clean up
    for (int i = 0; i < index; ++i) {
        delete[] myNodes[i];
    }
    delete[] myNodes;
//    delete[] nameNodes;


    return 0;
}

void genNode(int **x[], int n){
    /*Formating
        [0] D
        [1] I
        [2] E
        [3] x
        [4] y
    */
    (*x)[n][0] = NULL;
    (*x)[n][1] = NULL;
    (*x)[n][2] = NULL;
    (*x)[n][3] = rand() % 1000 + 1;            //random x coordinate between 0 and 1000
    (*x)[n][4] = rand () % 1000 + 1;           //random y coordinate between 0 and 1000
}
c++
arrays
exception
dynamic-memory-allocation

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0