0xC0000005

Hi!
I'm kind of new to c++ programming but i need to finish something that doesn't seem to work properly. This problem only occurs when i try to fill my array with certain values and only if there are more than six of them. After i run the program it seems like it's working fine but it returns with 0xC0000005 (or sometimes 0xFF?) and crashes. I really hope you can help me since it'd be really important for me.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
int numbers_of_survey(int n, int array[], int max, int good_survey[])
{
    int n=0;
    int i=0;
    for (i; i<max; i++){

        if (array[i]<=800 && i != max-1) {
            good_survey[n]=i+1;
            n=n+1;


            for (int k=i; k<max; k++) {

                if(array[k]>800 && k!=max-1) {
                    good_survey[n]=k-1+1;
                    n=n+1;
                    i=k;
                    k=max-1;
                }

                else if(array[k]>800 && k==max-1){
                    good_survey[n]=k;
                    n=n+1;
                    i=k;
                    }
            }
        }
        else if (array[i]<=800 && i==max-1){
            good_survey[n]=i+1;
            n=n+1;
            good_survey[n]=i+1;
            n=n+1;
            }
    }
    return(n);
}
Last edited on
Please edit your post and use code tags - http://www.cplusplus.com/articles/jEywvCM9/

Your problem is occurs probably because you're trying to access an element in the array that doesnt exist. An out of bound as they say.

Remember that if you create an array like this int arr[5]. It between arr[0] and arr[4].
I've already edited my post as you said but it's still returning with that error code unless i use those certain values i was talking about before. Otherwise it's just working fine.
Can you give us the values of int n, and int max. Also how big the arrays are. Im guessing n and max are the sizes for array and survey
closed account (oGN8b7Xj)
What is the size of good_survey[]?
Alright, i've found the solution and the problem was indeed because of accessing a wrong element in the array as you said in the first place. Thank you very much!
Topic archived. No new replies allowed.