Please use code tags. Find more information about them here:
http://www.daniweb.com/techtalkforum...cement8-3.html
Your sorting algorithm is fundamently flawed:
for ( int next = 0; next < ArraySize; next++ )
{
if ( strncmp(Array[next],Array[next-1],3) == -1) I don't quite understand what you're doing here. In the first iteration of the loop,
next will be equal to 0, so the second parameter you'll be passing to strncmp() will be... Array[-1]. That won't work. I think that you might want
next to be initialized at 1.
{
Array[next] = Array[next];
Um, ok, so then why bother putting this line in at all?
}
if( strncmp(Array[next],Array[next-1],3) == 1)
{
Array[next] = Array[next - 1];
}
And if you're going to swap variables, you are going to need to have an "in-between" variable to hold the value of 1 while the other is being swapped. You're just loosing the value contained in
Array[next] with that statement right there.
And even fixing that, it still will not work, as you aren't implementing the
Bubble sort algorithm correctly (which is what it seems you're trying to do). This is what the Bubble sort does:
- Compares the first 2 values. If the second is smaller than the first, it swaps them.
- Keeps comparing and swapping through the whole list.
- Starts over, doing the whole process again.
- Depending on how large your list is, you may have to do this many times to get the entire list sorted.
If this seems redundant, it is. The bubble sort is one of the slowest sorting algorithms, although you probably don't need to worry about speed right now, as the list is relatively small.
Hope this helps