糟透了的冒泡法.Help~该如何解决

糟透了的冒泡法....Help~~~
#include"stdio.h"
#include"string.h"
main()
{
  char x1[1024];  
int i,j,n=0,temp;;  
scanf("%s",x1);
for(i=0;i<strlen(x1);i++)
for(j=0;j<strlen(x1)-i;j++)
if(x1[i]>x1[i+1])
{
temp=x1[i];
x1[i]=x1[i+1];
x1[i+1]=temp;
}
 
  for(i=0;i<strlen(x1);i++)
  printf("%c",x1[i]);
}


今天腦子像糨糊一樣 居然連冒泡法哪出錯了都不知道 求助大神們了
俺剛接觸C語言.....

------解决方案--------------------
C/C++ code

#include"stdio.h"
#include"string.h"
main()
{
char x1[1024]; 
int i,j,n=0,temp;; 
scanf("%s",x1);
for(i=0;i<strlen(x1);i++)
for(j=i+1;j<strlen(x1);j++)
if(x1[i]>x1[j])
{
temp=x1[i];
x1[i]=x1[j];
x1[j]=temp;
}

for(i=0;i<strlen(x1);i++)
printf("%c",x1[i]);
}

------解决方案--------------------
C/C++ code
#include<stdio.h>//mark
#include<string.h>//mark
main()
{
    char x1[1024]; 
    int i,j,n=0,temp;; 
    scanf("%s",x1);
    for(i=0;i<strlen(x1);i++)
        for(j=0;j<strlen(x1) - 1 -i;j++)//mark
            if(x1[j]>x1[j+1])//mark,i都换为j
            {
                temp=x1[j];
                x1[j]=x1[j+1];
                x1[j+1]=temp;
            }

    for(i=0;i<strlen(x1);i++)
        printf("%c",x1[i]);
}