文字列をループして、各文字の使用数をカウントするプログラムを作成しようとしています。問題は、配列を適切に保存できないことです。どんな助けでも大歓迎です。
int main()
{
string textRad = "";
int histogram[ANTAL_BOKSTAVER];
getline(cin, textRad);
berakna_histogram_abs(histogram, textRad);
cout << histogram[0] << endl;
cout << histogram[2];
return 0;
}
void berakna_histogram_abs(int histogram[], string textRad)
{
for(int i = 0; i < ANTAL_BOKSTAVER; i++)
{
histogram[i] = 0;
}
for(int i = 0; i < textRad.length(); i++)
{
for(int j = 0; j < ANTAL_BOKSTAVER; j++)
{
int antal = 0;
string alfabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if(char(toupper(textRad.at(i))) == alfabet.at(j))
{
antal++;
}
histogram[j] = antal;
}
}
}