This only appears to move one character even though it does a lot of thrashing around when I step through it. It looks like it's only executing the loops once, but the topmost character in the array is corect. It just like the others aren't moved at all.
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
void select(char *item, int count);
int main(void)
{
char s[80];
system("cls");
printf ("Enter a string: ");
gets(s);
select (s, strlen(s));
printf ("The sorted string is: %s\n", s);
return 0;
}
/* Select Sort */
void select(char *item, int count)
{
register int a, b, c;
char t;
for (a = 0; a < count - 1; ++a)
{
c = a;
t = item[a];
for (b = a + 1; b < count; ++b)
{
if (item[b] < t);
{
c = b;
t = item[b];
}
}
item[c] = item[a];
item[a] = t;
}
}
I'm brushing up on my troubleshooting skills right now, but I just can't see the problem. However this refresher training for me. I haven't done any C programming for 20 years.
The box has an AMD 3+ quad core processor running WinXPSP3. The C package is Borland Turbo C 2.01.
EDIT: I forgot to say that it compiles and links with no errors or warnings, and I'm using the Small memory model.