Thread: pointing to an array

  1. #1
    Registered User
    Join Date
    Mar 2010

    Exclamation pointing to an array

    i was wondering is someone could give me a brief overview and maybe an example of how i would random pull out two vairiable from an array

    for example:
    i have an array stored with names= faceName[13]
    and one with suits= suitName[4]

    and i want to use a printf function to print out;(random faceName, random suitName.)

    i am using srand and everything is stored in my array i just dont know too much about pointers to acces it.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    segmentation fault
    You don't really need a pointer, you can just pull the element by number.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    int array[N];
    int rdm = array[rand() % N];
    sth like the above, where rand() % N gives you a number from [0,N-1]

  4. #4
    Registered User
    Join Date
    Mar 2010
    explain how to randomly pull the element by number?

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    Quote Originally Posted by gloworm View Post
    explain how to randomly pull the element by number?
    you asking to explain the previous post or asking the question why the previous post is trying to explain this?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  3. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 10:33 AM
  4. Replies: 7
    Last Post: 11-25-2008, 01:50 AM
  5. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM

Tags for this Thread