arrays

This is a discussion on arrays within the C Programming forums, part of the General Programming Boards category; this is a rather easy problem,but i can't seem top get around it.how do i declare an array whose number ...

  1. #1
    Unregistered
    Guest

    arrays

    this is a rather easy problem,but i can't seem top get around it.how do i declare an array whose number of elements are variable and has to be input by the user?

  2. #2
    B26354 Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633
    Using malloc() and an array of pointers comes to mind. Post what you have and we'll see what we can do.
    Jason Deckard

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Code:
    char *array;
    /* Get user input */
    array = malloc ( input *sizeof *array );
    .
    .
    .
    /* Always free your alocated memory */
    free ( array );
    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function to read in two arrays
    By ssmokincamaro in forum C Programming
    Replies: 7
    Last Post: 11-12-2008, 07:59 AM
  2. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 04:24 PM
  3. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  4. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM

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