home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_09_06
/
9n06024a
< prev
next >
Wrap
Text File
|
1991-02-17
|
509b
|
37 lines
#include <stdio.h>
#include <string.h>
#define NUMELEM(a) (sizeof(a)/sizeof(a[0]))
main()
{
char *list[] = {
"red",
"blue",
"yellow",
"green"
};
int i, j;
char *temp;
for (i = NUMELEM(list) - 2; i >= 0; --i) {
for (j = 0; j <= i; ++j) {
if (strcmp(list[j], list[j + 1]) > 0) {
temp = list[j];
list[j] = list[j + 1];
list[j + 1] = temp;
}
}
}
for (i = 0; i < NUMELEM(list); ++i)
printf("%s\n", list[i]);
}
blue
green
red
yellow