Argh!
This is what I am trying to do: read words from a file, and when the first and/or second letters of the words changes, store the number of words thus far encountered in the "indexes" integer array, with the indexes based on the first and second letters of the word last read.
I have had A LOT of trouble with this, and really don't know what I'm doing, and the compiler throws up errors (errors that are related to the code below). I've written the code as it makes sense to me, ignoring pointers and referencing/dereferencing stuff.
This is what I am trying to do: read words from a file, and when the first and/or second letters of the words changes, store the number of words thus far encountered in the "indexes" integer array, with the indexes based on the first and second letters of the word last read.
I have had A LOT of trouble with this, and really don't know what I'm doing, and the compiler throws up errors (errors that are related to the code below). I've written the code as it makes sense to me, ignoring pointers and referencing/dereferencing stuff.
Code:
int indexes[26][26];
int WordIndex=-1;
char firstLetter = "a";
char secondLetter = "a";
char newFirstLetter = "a";
char newSecondLetter = "a";
cout << currentWord;
ifstream fin("somefile.txt", ios::in);
string tempStr;
while (fin >> tempStr) {
wordIndex ++;
newFirstLetter = tolower(atoi(tempStr[0]));
newSecondLetter = tolower(atoi(tempStr[1]));
if (newSecondLetter != secondLetter) {
indexes[atoi(firstLetter) - 65][atoi(secondLetter) - 65] = wordIndex;
secondLetter = newSecondLetter;
}
if (newFirstLetter != firstLetter) {
indexes[atoi(firstLetter) - 65][atoi(secondLetter) - 65] = wordIndex;
firstLetter = newFirstLetter;
}
}
Comment