Thread: Get Random Item from 2D array and print it

  1. #1
    Registered User
    Join Date
    May 2020
    Posts
    1

    Get Random Item from 2D array and print it

    Hi, I'm wondering how I would get a random item from a 2D array and print just that item? For example, if I had a 2D Array like:
    Code:
    char questions[4][60] = {{How can I print item?}, {In a random order?}, {Is it possible?}, {Or Am I really foolish?}
    };
    I want the output to be:
    Is it possible?
    But I have to randomly get its indexes and print it.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,345
    In this case you can see your 2D array of char as a 1D array of strings, upon which the problem becomes a matter of generating a single random index.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do i get this program to print random numbers?
    By Santac in forum C Programming
    Replies: 19
    Last Post: 12-01-2017, 05:13 PM
  2. variable.item or array[named] possible?
    By cafrow in forum C++ Programming
    Replies: 6
    Last Post: 02-14-2005, 10:30 AM
  3. trying to remove item from an array
    By rugger78 in forum C++ Programming
    Replies: 6
    Last Post: 10-15-2004, 10:26 AM
  4. print Random Files
    By swishiat.com in forum C Programming
    Replies: 4
    Last Post: 12-15-2003, 01:58 PM
  5. Can't display item from an array
    By grscot in forum C++ Programming
    Replies: 16
    Last Post: 05-06-2003, 11:04 AM

Tags for this Thread