刚写了一个用冒泡排序排按字母表顺序整理字符串,遇到些问题求教
我想依据asc2中字母值大小做冒泡排序,给录入的字符串重按字母表顺序排序,结果打印出一行烫烫烫烫请问问题出在哪里?
#include<stdio.h>
main()
{
char initial[30] , t;
int outer, inner,didchange = 0;
puts("please write less than 30 letters\n");
gets(initial);
/* mao pao pai xu */
for(outer = 0;outer < (sizeof(initial)-1); outer++)
{
for(inner = outer; inner < sizeof(initial); inner++)
{
if( initial[outer] > initial[inner])
{
t = initial[outer];
initial[outer] = initial[inner];
initial[inner] = t;
didchange=1;
}
}
if(didchange = 0)/* ti qian jie su*/
{break;}
}
initial[(sizeof(initial)+1)] = "\0";
printf("%s",initial);
}