Alright, two questions here. First off I have a dictionary.h file and a HashDictionary.h and BinSearchDictionary.h each of which inherits from dictionary. What I want to do is have a variable dict which is either a HashDictionary object or a BinSearchDictionary object depending on the argument passed to the command line. What AI have right now is this:
Dictionary * dict;
if (hash)
dict=new HashDictionary();
else
dict=new BinSearchDictionary();
When I try to compile I get an error: Variable dict is not a structure. Any ideas on how to fix this?
Second Question
I am trying to sort an array of strings(char **) using qsort. I copy the strings into the array using strncpy and they copy fine. When I sort I get a weird output. Below is the code and the elements of the string after sorting.
// stringArray is passed into the function as char * stringArray[],
//and contains{"Apple","Hello","World","Here","I","Am",N ULL}
char ** pa=(char **)stringArray;
int x=0;
while (pa[x]!=NULL)
{
strncpy((char *)(_dictionary+numElems),pa[x],2048);
x++;
numElems++;
}
qsort((void *)_dictionary,numElems,sizeof(char *),comp);
return 1;
And the Contents of _dicitonary after qsort:
Am
ApplHellHereI
HellHereI
HereI
I
Worl
Does anyone know what the problem is here? Thanks for the help in advance.