Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runtime error

Status
Not open for further replies.

Mungovan

Programmer
Oct 24, 2002
94
IE

Hi.
I have this c program that creates a bunch of structures and fills them. When I compile it it's grand.

But when I run the program it output the desired results but says:

"An application error has occured...

Exception: access violation (0xc0000005), Address (0x0040f490) "


Anyone have any ideas of what's goin on???


Thanks,
D
 
Most likely you've done something untoward with pointers. ______________________________________________________________________
TANSTAAFL!
 
hi ..

exceptions are almost always to do with accessing something outside of your process boundary.

could be your stack if you have one. {pointers} -> make sure what your indexes are accesssing .. have you allocated ENOUGH memory ?

br:
 
Hi.
Thanks for the help. I am using alot of pointers to structures etc. Basically this is the brunt of my code (leaving out all the usual parts):


typedef struct node_t {
int x;
int y;
} node;

node *grid[100][100]; // 2D matrix of "node" pointers





for (x=0; x < SIZE; x++) // Initialise all pointers to NULL
{
for (y=0; y < SIZE; y++){
grid[x][y] = NULL;
}
}




for (i=0; i < POPULATION; i++){ // for each &quot;node&quot;
do
{
positionX = (rand() % 100);
positionY = (rand() % 100);
} while (grid[positionX][positionY] != NULL);
// loop until you find an empty space on the matrix


nodeLocation = (node*)malloc(sizeof(node));
grid[positionX][positionY] = nodeLocation;

nodeLocation->x = positionX;
nodeLocation->y = positionY;


// finally I want to print out the results:
for (i=0; i < POPULATION; i++){
for (j=0; j < POPULATION; j++){
printf(&quot;%d\t%d\t&quot;,grid[j]->x, grid[j]->y)
}
}







Any Ideas???????

Thanks,
D
 
Instead of this :
// finally I want to print out the results:
for (i=0; i < POPULATION; i++){
for (j=0; j < POPULATION; j++){
printf(&quot;%d\t%d\t&quot;,grid[j]->x, grid[j]->y)
}
}


do this :
// finally I want to print out the results:
for (i=0; i < SIZE; i++){
for (j=0; j < SIZE; j++){
printf(&quot;%d\t%d\t&quot;,grid[j]->x, grid[j]->y)
}
}

/JOlesen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top