Randomizing a person's name

This is a discussion on Randomizing a person's name within the C++ Programming forums, part of the General Programming Boards category; Hello, I'm using some of the lines of code from the tutorials on strings but I have a question. Is ...

  1. #1
    Naz
    Naz is offline
    Registered User
    Join Date
    Nov 2010
    Posts
    1

    Randomizing a person's name

    Hello,

    I'm using some of the lines of code from the tutorials on strings but I have a question.


    Is it possible to take the user's entry of first and last names and shuffle it? Including the location of where the space is?

    A finger pointing towards the direction of my answer would be most appreciated.

  2. #2
    Registered User Swarvy's Avatar
    Join Date
    Apr 2008
    Location
    United Kingdom
    Posts
    195
    One possibility would be to use the C strtok() function to separate the strings out into the first and last names:
    Code:
    /* Assume the first and last name is stored within a C++ string, temp_str */
    temp_ptr = strtok(temp_str.c_str(), " \n");
    /* temp_ptr points to first name */
    temp_ptr = strtok(NULL, " \n");
    /* temp_ptr now points to surname */
    That isn't a very 'clean' way of doing it if you ask me - too much mixing of C with C++ for my liking. You could alternatively use the istream::getline() method. but parsing the string using strtok is probably the single easiest way of doing it.

    Once you have the individual first and last names of a person, shuffling them is easy.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. randomizing arrays!!
    By vulock_ka in forum C Programming
    Replies: 15
    Last Post: 08-02-2010, 12:52 PM
  2. Randomizing dealing program C
    By BSmith4740 in forum C Programming
    Replies: 2
    Last Post: 08-04-2008, 02:42 PM
  3. randomizing
    By zanderela in forum C Programming
    Replies: 2
    Last Post: 03-21-2008, 02:54 AM
  4. searching a person's HD
    By abrege in forum C++ Programming
    Replies: 4
    Last Post: 04-10-2003, 06:46 AM
  5. persons and people
    By Sekti in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 06-26-2002, 04:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21