Jump to content
  • Advertisement
Sign in to follow this  
Dark Piper

Access Violation!!! Help Plz

This topic is 4951 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm using trying to write a program for my C++ class that reads student records and outputs a lot of stuff about them. Everything's basically working except that when I try to output the honour roll students, failers and those who missed two or more assignments the compiler is giving me an error message: "An Access Violation (Segmentation Fault)raised in you program." On the line where I'm getting this I'm trying to output a vector location: cout << honour[j]

Share this post


Link to post
Share on other sites
Advertisement
The line of code you showed tells me you're using a loop. My guess is, that you're reading outside of your array, in memory that's not yours. For instance, the following code will throw an access violation:


int IntArray[5] = {0, 1, 2, 3, 4 }; // Create array and fill it

// Loop the array and display the values:
for (int nLoop = 0; nLoop < 8; nLoop++)
{
cout << IntArray[nLoop] << endl;
}


As you can see, there are only 5 items in the array, and the loop runs 8 times. The last 3 items are outside the array(Or, out of bounds in programmer talk). This will read memory that is not part of your program, and will crash your application.

Toolmaker

Share this post


Link to post
Share on other sites
taking from toolmaker's point, you may have done this:

int IntArray[5] = {0, 1, 2, 3, 4 }; // Create array and fill it

// Loop the array and display the values:
for (int nLoop = 1; nLoop <=5; nLoop++)
{
cout << IntArray[nLoop] << endl;
}

this will also create an error, I used to do this all the time

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!