pointing to an array

This is a discussion on pointing to an array within the C Programming forums, part of the General Programming Boards category; i was wondering is someone could give me a brief overview and maybe an example of how i would random ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    41

    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
    Location
    segmentation fault
    Posts
    8,300
    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
    Posts
    1,853
    Code:
    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
    Posts
    41
    explain how to randomly pull the element by number?

  5. #5
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    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?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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, 12: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


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