#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char rand(char x);
int main()
{
char input[80] = {0};
char rando[80] = {0};
char choice = 0;
char rando2[80] = {0};
if(strlen(input) >= 10 && strlen(input) <= 80); {
printf("Please enter a string with 10-80 characters: ");
scanf("%s", input);
printf("Orginal string: %s\n", input);
rando = my_rand(input);
printf("New string: %s\n", rando); }
else{
return 0; }
printf("Would you like to shuffle this string again?(y or n): ");
scanf("%c\n", &choice);
if( choice == 'y') {
rando2 = my_rand(rando);
printf("New string: %s\n", rando2);
}
else if {
printf("Would you like to shuffle another string?(y or n): ");
scanf("%c\n", &choice2); }
if(choice2 == 'y') {
printf("Please enter a string with 10-80 characters: ");
scanf("%s", input2);
printf("Original string: %s\n", input2);
char rando3 = my_rand(rando2);
printf("New string: %s\n", rando3); }
else:
return 0;
return 0;
}
大家好,我的目标是根据需要多次随机播放用户输入字符串,提示是否继续。我很难弄清楚如何洗牌,有人可以帮忙吗?
这是示例输出:
Please enter a string with 10-80 characters:
initialnaivepassword
Original string: initialnaivepassword
New string: ntlvdiepnaaorsiiiwas
Would you like to shuffle this string again:y
New string: saiiwndrvpaiioneslat
Would you like to shuffle this string again:n
Would you like to shuffle another string? :y
Please enter a string with 10-80 characters:
anothernaivepassword
Original string: anothernaivepassword
New string: svdoanoprhsterneaaiw
Would you like to shuffle this string again:y
New string: eaapnrtwhrosvidosaen
Would you like to shuffle this string again:n
Would you like to shuffle another string? :n