I present a __128-char C__ solution without using any built-in sorting and ToLower functions: i,j;main(k){char s[99];gets(s);for(;i<strlen(s);){j=i-1;k=s[i++];while(j>=0&&(s[j]|32)>(k|32))s[j+1]=s[j--];s[j+1]=k;}puts(s);} More readable version: i,j; main(k) { char s[99]; gets(s); for(;i<strlen(s);) { j=i-1; k=s[i++]; while( j>=0 && (s[j]|32)>(k|32) ) s[j+1]=s[j--]; s[j+1]=k; } puts(s); }