I am writing a program that takes an array of pointers to strings and I am writing a function to put them in order. I think I have the ground work of bubble sort, but all the items in the list are just switching one position instead of being sorted.
Here is main
char *bubble[5] = { "cats", "dogs", "bananas", "apples", "sugar" };
int i = 0;
for (i = 0; i < 5; i++)
{
printf("%s ", bubble[i]);
}
printf("\n");
bubble_sort(bubble, 5);
i = 0;
for (i = 0; i < 5; i++)
{
printf("%s ", bubble[i]);
}
printf("\n");
and here is my function
void bubble_sort(int *list[], int size)
/*
This sorts a list of strings
*/
{
int u = 0, c = 0, passes = 0;
char *temp = '/0';
u = size - 1;
while (u > 0)
{
c = 1;
while (c < u)
{
if (strcmp(list[c], list[c - 1]))
{
temp = list[c];
list[c] = list[c-1];
list[c - 1] = temp;
c++;
}
u--;
}
}
}
I guess my problem is getting the pointers to change the contents of the bubble array so that I can print in main