0

I was looking for some help in sorting an Array. I have to do it this way, but I am getting some error messages I am not understanding such as:

  1. [WARNING name lookup of 'index' changed .
  2. matches this 'char* index[const char*, int] undr ISO standard rules
  3. matches this index under old rules
  4. invalid types 'int&[char()(const char*, int)] for array subscript
  5. at global scope

I have some suspicion of what it is but a little lost of how to fix it. The file I am opening is sentence that reads: Oliver was a Golden Retreiver whose fur was long and golden.

As you can tell I am a complete beginner so any tips will be greatly appreciated Thanks in advance!

#include <iostream>
#include <fstream>
using namespace std;
void swap_values(int& v1, int& v2);
int index_of_smallest(int list[],int start_index, int number_used);
void initialize(int list[]);
void Sort(int list[],int&num);
void characterCount(char ch, int list[]);
void readText(ifstream& intext, char& ch, int list[]);
void totalCount(int list[]);
int main()
{
    int index,letterCount[26];
    char ch;
    ifstream inFile;
    ofstream outFile;

    cout<<"This is the text of the file:"<<endl;

    outFile.open("C:/temp/Data_Chapter_7_8.txt");
    if(!outFile)
    {
        cout<<"Cannot open file."<<endl;
    }       

    inFile.open("C:/temp/Data_Chapter_7_8.txt");

    if (!inFile)
    {
       cout << " Cannot open file." <<endl;
    }
    initialize(letterCount);
    inFile.get(ch);

    while (inFile.get(ch))
    {
        int index;
        readText(inFile,ch,letterCount);
        index++;
    }
    totalCount(letterCount);

    inFile.close();

    system("PAUSE");
    return 0;
}
void initialize(int list[])
{
    for(int x = 0;x<26;x++)
    list[x] = 0;
}
void characterCount (char ch, int list[])
{
    ch = tolower(ch);
    if(static_cast<int>(ch)>=97&&(static_cast<int>(ch)<=122))
    list[static_cast<int>(ch)-97]++;
}
void readText(ifstream& intext, char& ch, int list[])
{ 
    if (ch != '.')
    {
        characterCount (ch,list);
    }
}
void totalCount(int letterCount[])
{
    for(int x=0;x<26;x++)
        if(letterCount[x]>0)  
            cout<<static_cast<char>(x+97)<<" "<<letterCount[x]<<endl;
}
void Sort(int list[], int number_used)
{
    int index_of_next_smallest;
    for(int index= 0; index<number_used -1; index++)
        index_of_next_smallest = index_of_smallest(list, index,number_used);
     swap_values(list[index],list[index_of_next_smallest]);
}
}
int index_of_smallest(int list[], int start_index, int number_used);
{
    int min = list[start_index];
    index_of_min = start_index;
    for (int index= start_index + 1; index < number_used; index++)
        if (list[index]>min)
        {
            min = list[index];
            index_of_min = index;
        }
    return index_of_min;
 }   
 void swap_values(int& v1, int& v2)
 {
     int temp;
     temp = v1;
     v1 = v2;
     v2 = temp;
 }
2
  • I strongly suggest you don't use the same name for two different variables. This will fix at least half your problems right off the bat. Commented Nov 18, 2012 at 3:27
  • ok i have done that, now I am getting an erro of name lookup of index1 changed for new ISO 'for' scoping. And "using obsolete binding and index1" Commented Nov 18, 2012 at 3:40

1 Answer 1

1

Inside your Sort function, change

for(int index= 0; index<number_used -1; index++)

to

int index;
for(index = 0; index < number_used-1; index++)

because you need to access index after the loop ends.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, the program is compiling though is showing a blank screen, any tips on how to debug this?
@user1705380 try stepping through it with a debugger.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.