Bus Error when running

Hi,
i have a function that works fine except that after it have executed everything it says "Bus error:10".

I can't seem to find anything wrong with it, but i'm guessing that you will! :)

Thanks for any help!

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
string Text::tolka()
{
double sprak[ANTAL_SPRAK];
string namn[ANTAL_SPRAK] = {"Engelska ", "Franska ", "Svenska ", "Tyska "};
for (int i=0; i<ANTAL_SPRAK; i++)
sprak[i]=0.0;

    for (int i=0; i<ANTAL_SPRAK; i++)
    {
        for (int j=0; j<ANTAL_BOKSTAVER; j++)
        {
            sprak[i]=sprak[i]+((TOLK_HJALP[i][j]-relhisto[j])*(TOLK_HJALP[i][j]-relhisto[j]));

        }
    }


cout << "Totala antalet bokstäver: " << antal << endl;
cout << "Kvadratsummorna:" << endl;
for (int i=0; i<ANTAL_SPRAK; i++)
cout << namn[i] << sprak[i] << endl;

int trolig=0;
for (int i=1; i<ANTAL_SPRAK; i++)
{
 if (sprak[i]<sprak[trolig])
    trolig=i;
}
cout << "Troligast är det: " << namn[trolig] << endl;
}
I can't make sense of all the names =P, but I can tell you something.

Arrays declared <typename><name>[<int>] (like all arrays) have elements <name>[<0 to int-1>], not <name>[<1 to int>]. In computer science, pretty much everything starts with 0, not 1. Trying to read a member of an array that doesn't exist results in a Bus Error.
Last edited on
Topic archived. No new replies allowed.