Sort the letters of string in alphabetical order: Difference between revisions
Sort the letters of string in alphabetical order (view source)
Revision as of 08:47, 31 January 2022
, 2 years agoAdd C
Not a robot (talk | contribs) (Add Draco) |
Not a robot (talk | contribs) (Add C) |
||
Line 201:
writef("%S*N", string)
$)</lang>
{{out}}
<pre>Now is the time for all good men to come to the aid of their country.
.Naaccddeeeeeeffghhhiiiillmmmnnooooooooorrrstttttttuwy</pre>
=={{header|C}}==
<lang c>#include <stdio.h>
/* Sort a character string in place */
void strsort(char *s) {
unsigned int n[256] = {0};
unsigned char i = 0;
char *t = s;
while (*s) ++n[(unsigned char) *s++];
while (++i) while (n[i]--) *t++ = (char) i;
}
int main() {
char s[] = "Now is the time for all good men "
"to come to the aid of their country.";
puts(s);
strsort(s);
puts(s);
return 0;
}</lang>
{{out}}
<pre>Now is the time for all good men to come to the aid of their country.
|