Access violation
im trying to run my program but i keep getting the following error:
0xC0000005: Access Violation
the program compiles and links fine its just this one error. i think it is a memory address. the odd thing is everytime i try and run it i get the same error. any ideas what could be wrong?
im using VC++ if it helps
I think you are trying to access an illegal memory address , i''m guessing by trying to write data into an array with the wrong array index. run your program in debug mode , it should show you the location of the bad code.
Errors like that are found only in run time and not while compiling.
Errors like that are found only in run time and not while compiling.
ok. i have done some more testing to find out what i did wrong. the funny thing is i didnt do anything wrong (at least i think so). anyway i made a couple of different programs. one was a console, another opengl, and a basic window. all of these returned the exact same address and returned the exact same error. is there something wrong with my compiler, or my computer?
quote:
Original post by adam17 is there something wrong with my compiler, or my computer?
some advice hard learnt,
you should absolutly never consdier a problem to be anything but your own fault.
as for your problem, debug your program. An access violation is one of the most, if not the most, basic form of run time error, so it should be very nice and obvious whats going wrong.
| - Project-X - my mega project.. getting warmer

if it was my problem why does it give me the exact same error at the same memory location every time. it even gives me the same error on different programs. i really dont think it is something wrong with the code.
March 29, 2003 12:02 PM
Well, post your code. Is it a really simple program that doesn''t even try to do anything?
this is the entire program. it consists of just a simple linked list.
if it doesnt give the error the first time recompile and run it again.
//#include "main.h"//#include "import.h"#include <iostream.h>#include <conio.h>#include <stdio.h>#include <stdlib.h>struct str1{ int num1; //str1 *str1_pnext;};struct str2{ str1 Str1; str2 *str2_pnext; //str2 *root;};void main(){ str2 *Str2; str2 *pStr2; int num_objects; int num, tnum; cout << "How many objects do you want? "; cin >> num_objects; //Str2.root = &Str2 for( int x=0; x<num_objects; x++) { Str2 = new str2; //Str2.Str1->num1 cout << "Enter a number for the node: "; cin >> num; cout << endl; Str2->Str1.num1 = num; } pStr2 = Str2; for( int y=0; y<num_objects; y++) { cout << pStr2->Str1.num1 << endl; pStr2 = pStr2->str2_pnext; }}
if it doesnt give the error the first time recompile and run it again.
Your linked list is not terminated with a NULL. This is causing the access violation error. In addition, your linked list does not "push" the items into the list, thus causing a large number of memory leaks. Also, your code assumes the number of links in the list. This is not a good idea. Here is the proper code for your project. I hope this helps. 
- EDIT - The code is now properly formatted.
[edited by - d3dicated on March 29, 2003 5:07:37 PM]

struct Node { int iNum; Node *pNext; };void main(void){ Node *pListStart = NULL; // The NULL will be 'pushed' in. Node *pTempNode = NULL; // Always set pointers to NULL. Node *pKill = NULL; int iTotalNodes = 0; cout << endl << "How many Nodes do you want?"; cin >> iTotalNodes; cout << endl; // Create and initialize the Nodes. for (int iX = 0; iX < iTotalNodes; iX++) { pTempNode = new Node; if (pTempNode) { cout << endl << "Enter a number : "; cin >> pTemp->iNum; // The next pointer points to the start of the list. pTempNode->pNext = pListStart; // The start of the list will point to the new Node. pListStart = pTempNode; } } // Display the list. pTempNode = pListStart; while (pTempNode) { cout << endl << "Node Data : " << pTemp->iNum; pTempNode = pTempNode->pNext; } // Destroy the memory, and prevent memory leaks. pTempNode = pListStart; while (pTempNode) { pKill = pTempNode; pTempNode = pTempNode->pNext; delete pKill; }}
- EDIT - The code is now properly formatted.
[edited by - d3dicated on March 29, 2003 5:07:37 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement