String and Array of Characters

Hey Guys Can you help me make a Program, Cause this is very hard for me as a newbie. So the program would be like this. Whenever i Entered a Word, for example Airplane, its outcome will become= Aaerplani. So its like the outcome will be jumbled based from the word entered. Im using C languange, Thanks in Advance Programmers
Uhm Yeah, Jumble. Thats what I meant. Thanks for the Info btw :)
Can you help me with the Shuffe in C Language? I cant understand it Thanks
This?
1
2
3
4
5
6
7
8
9
10
template <class RandomAccessIterator, class RandomNumberGenerator>
  void random_shuffle (RandomAccessIterator first, RandomAccessIterator last,
                       RandomNumberGenerator& gen)
{
  iterator_traits<RandomAccessIterator>::difference_type i, n;
  n = (last-first);
  for (i=n-1; i>0; --i) {
    swap (first[i],first[gen(i+1)]);
  }
}

First, it is a template function. We can simply drop the first line, but we have to replace the word RandomAccessIterator with a real type. A C-string is an array of characters and thus the real type is char *.

Similarly, the gen is a function that we don't need to pass as parameter.
We have char pointers, so the difference_type can be int.
1
2
3
4
5
6
7
8
void random_shuffle (char * first, char * last)
{
  int i, n;
  n = (last-first);
  for (i=n-1; i>0; --i) {
    swap( first[i], first[gen(i+1)] );
  }
}

It still depends on functions swap and gen. The usage example of random_shuffle has function myrandom. Can you figure out how to swap values?
Topic archived. No new replies allowed.