#include <iostream>
#include <cstring>
#include <fstream>
using namespace std;
const int length = 25;
void insertionSort(int numb, char* anArray[])
{
char temp[length];
int pos;
for(int i = 1; i < numb; i++)
{
strncpy(temp, anArray[i], length);
pos = i;
//moves "higher" letters to the right
while(pos > 0 && strnicmp(anArray[pos-1],temp,length) > 0)
{
strncpy(anArray[pos],anArray[pos - 1],length);
pos --;
}
strncpy(anArray[pos],temp,length);
}
}
int main()
{
ofstream file;
file.open("Alphabetize.doc");
int num;
cout << "How many names do you want to enter? ";
cin >> num;
char *sortArray= new char [num];
file << "Original Word List: " << endl;
for (int i=0; i<num; i++)
{
cout << "\tInput word: ";
cin >> sortArray[i];
file << sortArray[i] << endl ;
insertionSort(num,sortArray[i]);
}
file << "\n\nSorted List:\n";
for(int i = 0; i < num; i++)
file << sortArray[i] << endl;
return 0;
}
ERROR: invalid conversion from `char' to `char**' initializing argument 2 of `void insertionSort(int, char**)'
I have an idea of what the error is, in that when I am calling the function, I am passing the wrong arguments. (I can read). I have tried googling for help (to understand it so I can 1, fix it and 2, not make it again), I have read my c++ book I feel like 1,000 times. I can't seem to figure out how to fix it. :$
I have tried different combinations of * and & to reference and dereference the char, since I couldn't understand what the book was telling me about it. So far, nothing is working! I'm getting VERY frustrated.
Obviously, the goal of the program (and yes, it is a school project) is to alphabetize an input list of names, the length of the list to be determined by the user. I thought string would work better than char, but the assignment says to use "char *names[]", so I'm using that (though with a different name).
I'd appreciate any help in understanding wtf I need to do. I'm tired of this error!
Thanks!!!!