I have a program I am working on that is basically like this:
bool isUnique(char**,int,char[]);
int main() {
char** uniqueWords = new char *[MAXWORDSIZE];
uniqueWords[posofUnique] = new char[MAXWORDSIZE];
//assign value to uniqueWords[0]="value"
isUnique(uniqueWords,posofUnique,currentWord);
}
bool isUnique(char **uniqueArray, int amountofArrayFilled, char currentWord[]){
for (int count =0; count < amountArrayFilled; count++){
bool isEqual = strcmp(uniqueArray[count],currentWord);
}
return false;
}
however uniqueArray only loads in one character on strcmp. How do I get it to load the entire array?
Your
uniqueWordsarray hasMAXWORDSIZEelements and all of them contain garbage pointer values immediately after allocation.Then you set
uniqueWords[posofUnique]pointer to some newly allocated memory. So, that single entry now holds some more-or-less meaningful value. The other entries ofuniqueWordsarray still contain garbage values.Then you call
isUnique, which attempts to inspect array entries fromuniqueWords[0]touniqueWords[posofUnique - 1]. But these entries still contain meaningless garbage values!So, whatever you see through these non-initialized entries means absolutely noting. It is just some unpredictable garbage at some random address in memory. You say you see “only one character” there? Congratulations. With the same degree of success you can discover the lost proof of Fermat’s Great Theorem there.