Thread: A question about arrays

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    92

    A question about arrays

    Hello

    My question is that is it possible for the user to decide which array element they want to input the data into.

    A printf statement can ask the user which element they want to put the data into. Say an array of 9 elements is defined is it possible that user can choose to put data in the 5th element.

    I would appriciate any help anybody can give me.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >is it possible for the user to decide which array element they want to input the data into.
    Yes.
    My best code is written with the delete key.

  3. #3
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    get the number and put into a variable, say inputnum. Let's assume the "data" is an int named mydata:
    Code:
    int myarray[9];
    myarray[inputnum] = mydata;
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  4. #4
    Registered User SKeane's Avatar
    Join Date
    Sep 2006
    Location
    England
    Posts
    234
    But don't forget to check that the user doesn't supply an array element number that is out of bounds.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about arrays.
    By Kelvie in forum C++ Programming
    Replies: 3
    Last Post: 09-17-2007, 05:32 AM
  2. A question concerning character arrays
    By ellipses in forum C Programming
    Replies: 3
    Last Post: 03-08-2005, 08:24 PM
  3. Replies: 6
    Last Post: 04-26-2004, 10:02 PM
  4. Question about char arrays
    By PJYelton in forum C++ Programming
    Replies: 5
    Last Post: 10-21-2003, 12:44 AM
  5. Question about arrays?? PLease read..
    By foofoo in forum C Programming
    Replies: 3
    Last Post: 06-24-2002, 02:40 PM