没太看懂题目的意思
字典顺序是什么
要如何按照字典顺序输出字符呢
就是ASCII码的顺序排序,用strcmp函数比较排序就可以了。
代码如下:
#include <stdio.h>
#include <string.h>
void sort(char (*p)[80],int n)
{
int i,j;
char t[80];
for (i=0;i<n-1;i++)
{
for (j=0;j<n-i-1;j++)
{
if (strcmp(p[j],p[j+1])>0)
{
strcpy(t,p[j]);
strcpy(p[j],p[j+1]);
strcpy(p[j+1],t);
}
}
}
}
int main()
{
char s[5][80];
int i;
printf("请输入5个字符串:\n");
for (i=0;i<5;i++)
{
scanf("%s",s[i]);
}
sort(s,5);
printf("排序后:\n");
for(i=0;i<5;i++)
printf("%s\n",s[i]);
return 0;
}