#include <stdio.h>
#include <string.h>
char sword[128][256];
int getWords(char *str)
{
int i = 0;
char *p;
for(;;)
{
if(0 == i)
p = strtok(str, " ");
else
p = strtok(NULL, " ");
if(NULL == p)
break;
strcpy(sword[i], p);
i ++;
}
return i;
}
int sortWords(int num)
{
int i = 0, j = 0;
char strtmp[256];
for(i = 0; i < num - 1; i++)
{
for(j = i + 1; j < num; j ++)
{
if(stricmp(sword[i], sword[j]) > 0)
{
memset(strtmp, 0x00, sizeof(strtmp));
strcpy(strtmp, sword[i]);
strcpy(sword[i], sword[j]);
strcpy(sword[j], strtmp);
}
}
}
return 0;
}
int main(int argc, char *argv[])
{
int i = 0, iNum = 0;
char sbuf[2048+1];
memset(sbuf, 0x00, sizeof(sbuf));
printf("Please Enter your string: ");
gets(sbuf);
iNum = getWords(sbuf);
sortWords(iNum);
for(i = 0; i < iNum; i++)
{
printf("%s ", sword[i]);
}
printf("\n");
return 0;
}