Two dimentional array in C++ Form Application

I'm using C++ Form Application in Visual Studio 2010. My question may be weird and funny for you but at first, I have to say that I'm not beginner in C++ :). I defined a new two dimentional array. like this "static int dizi[26][26];" I want to change the value when I clicked the button1. For example, I can change as dizi[2][3]=1. But I couldn't change like in this code. dizi[a][b]=1 didn't happen. Error is... "access violation exception was unhandled. attempted to read or write protected memory. this is often an indication that other memory is corrupt."

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
for(int i=1;i<=26;i++)
{
	uzunluk=0;
	for(int uzun=1;uzun<=26;uzun++)
	{
         if(ogrenci[i].ders[uzun]!=0)
         uzunluk+=1;
         else break;
         }

        for(int j=1;j<uzunluk+1;j++){
         for(int x=j+1;x<uzunluk;x++){

if(ogrenci[i].ders[j]!=ogrenci[i].ders[x])
{
dizi[ogrenci[i].ders[j]][ogrenci[i].ders[x]]++; //error
dizi[ogrenci[i].ders[x]][ogrenci[i].ders[j]]++; //error
                    
}}}}


I don't use zeroth variable here.So, It started from 1. My problem is variable can't be changed.I can't assign a value to variable. I have to use 'ogrenci[i].ders[j]'s index for dizi array in this code. It's really weird. I tried lots of things. Please help. Thank you..
Well you're definitely going to have problems if you declare a 2d array as:

 
dizi[26][26]


and you intend to iterate through it from index 1 to 26. This because in C++ we almost always count from zero [0]. Why do you want to try and change the rules?

So to iterate through any array of 26 you would need to start at index zero [0] and finish at [25].
Last edited on
Topic archived. No new replies allowed.