Exception when accessing an array element

This is just weird. I'm trying to iterate through an array of structures, passed as a pointer like so:

void creeaza(Digraf* d,char* filename)

Where the type Digraf is defined through these structures:

 typedef struct l{

 int nr;

 l* next;

 }*LIST_AD;

 typedef struct{

 LIST_AD laI; //first element if internal list

 LIST_AD laE; //first element of external list

 LIST_AD lvf;

 }HEAD;

 typedef HEAD Digraf[1000];

Now when trying to do the following inside the above-mentioned creeaza function, the program crashes. Well to be more specific, the first printf statement works, all the addresses are displayed correctly. However, inside the for loop, when i becomes 2, the program crashes and throws an exception at the line directly under the for statement. Could anyone tell me what's going on Thanks in advance.

#ifdef DEBUG

printf("d[0], d[1], d[2], d[3]: %p %p %p %p\n",&d[0], &d[1], &d[2], &d[3]);

getc(stdin);

#endif

for(i = 0; i < n; i++){

d[ i ] -> laE = d[ i ] ->l aI = d[ i ] -> lvf = NULL;

[...] //some code ommitted

}



Answer this question

Exception when accessing an array element

  • Joachim Meyer

    Do you think I have not tried debugging before posting here I only ask a question as a last resort, and the inconclusive hours spent trying to figure out what is happening kind of prove that this is a bit too much to handle at the moment. Thank you for the recommendation, I am of course attempting further debugs while I'm waiting. If you cannot help or don't want to, feel free not to post.
  • RyanRos

    Then please post EXACTLY what your debugging efforts have indicated.

    Ronald Laeremans
    Visual C++ team


  • Yovav

    This is what a debugger is for - step through your code line by line and confirm that the program is doing exactly what you think it is doing - you'll probably discover that it isn't.

  • Exception when accessing an array element