习题8-7 字符串排序 (20分)
代码:
#include <stdio.h>
#include <string.h>
int main()
{
char str[5][81];
int i = 0, j = 0;
for (i = 0; i < 5; i++) scanf("%s", &str[i]);
for (i = 0; i < 4; i++)
{
for (j = i + 1; j < 5; j++)
{
if (strcmp(str[i], str[j]) > 0) {
char ch[81];
strcpy(ch, str[i]);
strcpy(str[i], str[j]);
strcpy(str[j], ch);
}
}
}
printf("After sorted:\n");
for (i = 0; i < 5; i++) printf("%s\n", str[i]);
return 0;
}