This code is designed to work, not necessarily to be efficient. If it does not work, point me in the right direction, please, or tell me how (and why!) a certain fix would work.
This code is meant to delete duplicates in an array of strings and order them by collating sequence.
Example:
If given the strings "africa", "asia", "africa", "europe"
you would get back:
"asia", "africa", "europe"
void sortUnique (char** pWords) {
char* temp;
int cmp;
for(int i = 0; pWords[i]; i++) {
for(int j = (i+1); pWords[j]; j++) {
cmp = strcmp(pWords[i], pWords[j]);
if(cmp > 0) {
temp = pWords[j];
pWords[j] = pWords[i];
pWords[i] = temp;
} else if(cmp == 0) {
pWords[j] = NULL;
}
}
}
}