$ cat shuffle.c
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <time.h>
#define utf8_head(c) (((c) & 0xC0) != 0x80)
int
main(void)
{
char input[BUFSIZ], *runes[BUFSIZ];
char output[BUFSIZ];
size_t len, i, j;
char *ptr;
fgets(input, sizeof(input), stdin);
fclose(stdin);
ptr = input;
while(*ptr) {
if (utf8_head(*ptr) && *ptr != '\n') {
runes[len] = ptr;
len++;
}
ptr++;
}
srand((unsigned)time(NULL));
for(i = 0; i < len - 1; i++) {
j = i + rand() % (len - i);
ptr = runes[j];
runes[j] = runes[i];
runes[i] = ptr;
}
ptr = output;
for(i = 0, ptr = output; i < len; i++) {
j = 0;
do {
*ptr = *(runes[i] + j);
j++;
ptr++;
} while(!utf8_head(*(runes[i] + j)));
}
*ptr = '\n';
*(ptr + 1) = '\0';
fputs(output, stdout);
return EXIT_SUCCESS;
}
$ gcc -Wall shuffle.c && echo ねむいね | ./a.out
いむねね
むっちゃ長くなったw
@zundan Cat shuffle