Note that there are some explanatory texts on larger screens.

plurals
  1. POstrcat error "Unhandled exception.."
    primarykey
    data
    text
    <p>My goal with my constructor is to:</p> <p>open a file read into everything that exists between a particular string ("%%%%%") put together each read row to a variable (history) add the final variable to a double pointer of type char (_stories) close the file.</p> <p>However, the program crashes when I'm using strcat. But I can't understand why, I have tried for many hours without result. :/</p> <p>Here is the constructor code:</p> <pre><code>Texthandler::Texthandler(string fileName, int number) : _fileName(fileName), _number(number) { char* history = new char[50]; _stories = new char*[_number + 1]; // rows for (int j = 0; j &lt; _number + 1; j++) { _stories[j] = new char [50]; } _readBuf = new char[10000]; ifstream file; int controlIndex = 0, whileIndex = 0, charCounter = 0; _storieIndex = 0; file.open("Historier.txt"); // filename while (file.getline(_readBuf, 10000)) { // The "%%%%%" shouldnt be added to my variables if (strcmp(_readBuf, "%%%%%") == 0) { controlIndex++; if (controlIndex &lt; 2) { continue; } } if (controlIndex == 1) { // Concatenate every line (_readBuf) to a complete history strcat(history, _readBuf); whileIndex++; } if (controlIndex == 2) { strcpy(_stories[_storieIndex], history); _storieIndex++; controlIndex = 1; whileIndex = 0; // Reset history variable history = new char[50]; } } file.close(); } </code></pre> <p>I have also tried with stringstream without results..</p> <p>Edit: Forgot to post the error message: "Unhandled exception at 0x6b6dd2e9 (msvcr100d.dll) in Step3_1.exe: 0xC00000005: Access violation writing location 0c20202d20." Then a file named "strcat.asm" opens..</p> <p>Best regards Robert</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload