Process returned -1073741819 (0xC0000005) in code::blocks c++

0

I have a program that uses getline to populate an array of strings. When I run this program, it outputs the correct values from the getline(cin) and then the program crashes, issuing the error messege "Process returned -1073741819 (0xC0000005)" I understand that this code has to deal with accessing memory locations. I have tried using pointers, but everything that I have tried has caused the program to crash in the same manner. Can you please provide advice on what I can do to fix this issue?

I am using Code::Blocks for this program on windows 10

edit: I am putting the strings in an array to be tested for the number of similar words

    int wordCount = 0;
    cout << "Enter the number of words in your email: ";
    cin >> wordCount; //size of array determined by wordCount, which is retrieved from the user
    string testEmail[wordCount] = { }; // declaring and initializing the array
    cout << "Enter the email you wish to test: ";
    getline(cin >> std::ws, testEmail[wordCount]); // this will populate the array from user input
    cout << "The email that will be tested is: ";
    for(int i=0; i<wordCount; i++) // for loop used for testing
        cout << testEmail[i] << " ";
c++
arrays
asked on Stack Overflow Apr 26, 2020 by cmbtmstr • edited Apr 26, 2020 by cmbtmstr

1 Answer

0

0xC0000005 is the error code for an assert. Given your code the most likely assert to fire is validation that your array indexing is valid. As already pointed out in the comments testEmail[wordCount] is out of bounds as C++ arrays are index 0 based the "count" is one past the last valid index. The application is likely asserting this is invalid at runtime.

answered on Stack Overflow Apr 26, 2020 by DClyde

User contributions licensed under CC BY-SA 3.0