This is something similar, done a little differently.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
int main()
{
char command[20], jumbled[sizeof command * 4];
size_t i, j, k;
/*
* Set the random source.
*/
srand( (unsigned)time( NULL ) );
/*
* Prompt user.
*/
fputs("command>", stdout);
fflush(stdout);
/*
* Obtain user input.
*/
if ( fgets(command, sizeof command, stdin) )
{
char *newline = strchr(command, '\n');
if ( newline )
{
*newline = '\0'; /* strip trailing '\n' */
}
}
/*
* Jumble things up.
*/
for ( i = 0, k = 0; command[i] != '\0'; ++i )
{
jumbled[k++] = command[i]; /* add "real" data */
/*
* Insert 4 random characters.
*/
for ( j = 0; j < 4; ++j )
{
jumbled[k++] = rand() % 26 + 'a';
}
}
/*
* Display the result.
*/
puts(jumbled);
return 0;
}
/* my output
command>crap
cbrkmrkoxtabjorpxjik
*/