^^^ Probably want the sorting to be hand coded.
Code:
#include <stdio.h>
#include <stdbool.h>
//you'll need to add string.h to the include list
struct entry
{
char word[15];
char definition[50];
};
void dictionarySort(struct entry dictionary[], int n)
{
int i,j,k,l; //delete k and l
struct entry temp;
bool test;
for(i = 0; i < n - 1; ++i)
for(j = i + 1; j < n; ++j)
{
//test = true;
//for(i = 0; (dictionary[k].word[i] || dictionary[l].word[i] != '\0') && test; ++i)
/* add this */
if(strcmp(dictionary[i].word, dictionary[j].word)> 0) {
temp = dictionary[i];
dictionary[i]= dictionary[j];
dictionary[j] = temp;
}
/* because in C, you can't compare strings with an equal sign */
/* use the return value of strcmp(), instead */
/* delete this block of code
for(j = 0; dictionary[k].word[j] != '\0'; ++j)
temp.word[j] = dictionary[k].word[j];
for(j = 0; dictionary[l].word[j] != '\0'; ++j)
dictionary[k].word[j] = dictionary[l].word[j];
for(j = 0; temp.word[j] != '\0'; ++j)
dictionary[l].word[j] = temp.word[j];
test = false;
}
it isn't needed. You can swap a struct in total IF the struct
has no pointers in it.
If it has pointers, then whatever they point to has to be
swapped, one item at a time.
*/
}
}
int main(void)
{
struct entry dictionary[100] =
{ { "abyss", "a bottomless pit" },
{ "aardvark", "a burrowing African mammal" },
{ "acumen", "mentally sharp; keen" },
{ "addle", "to become confused" },
{ "aerie", "a high nest" },
{ "affix", "to append; attach" },
{ "agar", "a jelly made from seaweed" },
{ "ahoy", "a nautical call of greeting" },
{ "aigrette", "an ornamental cluster of feathers" },
{ "ajar", "partially opened" } };
int i;
void dictionarySort(struct entry dictionary[], int n);
printf("The original, unsorted dictionary:\n");
for(i = 0; i < 10; ++i)
printf("%s %s\n", dictionary[i].word, dictionary[i].definition);
dictionarySort(dictionary, 10);
printf("The sorted dictionary:\n");
for(i = 0; i < 10; ++i)
printf("%s %s\n", dictionary[i].word, dictionary[i].definition);
return 0;
}
Make those changes, and study up!