我在C中排序字符时遇到了一些问题。如果我想按从z到a的字母顺序对数组进行排序,它的工作原理很好。当我尝试做相反,从A到Z,它不工作。我可以利用一些帮助,谢谢;)C按字母顺序排列无论哪种
#include <stdio.h>
#include <string.h>
int main() {
char s1[10],a;
int i,t;
printf("enter a set to sort: ");
scanf("%s",s1);
t=1;
// printf("%d length of set",strlen(s1));
while (t==1)
{
// printf("a\n");
t=0;
for (i=0;i<strlen(s1);i++)
{
if (s1[i]<s1[i+1])
{
// printf("s");
t=1;
a=s1[i+1];
s1[i+1]=s1[i];
s1[i]=a;
}
}
}
printf("%s sorted",s1);
}
作品,谢谢! :) – user3395711
@ user3395711好的。阅读[this](http://stackoverflow.com/about)了解如何使用stackoverflow.accept一个正确的答案和投票任何有用的答案 – LearningC