Thread: 2 Array questions

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    19

    Question 2 Array questions

    1 Is there anyway to automatically get slices of arrays?

    For example, from the array {1 2 3 4 5 6} is there any quick way of getting say elements 2-4 in a new array {2 3 4}?


    2 Dynamic array size. I need an array which size is determined by argv first thing in the function. Do I need to start defining structures and pointers or is there a quicker way?

    Thanks a lot,

    Tor

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    If you're up for a read, this is a good intro into pointers and arrays.

    >>any quick way of getting say elements 2-4 in a new array
    memcpy() if the elements are contiguous. Or simple direct assignment for each element you want to copy.

    >>I need an array which size is determined by argv first thing in the function
    malloc() an array then.

    This will get you memory for 10 ints
    #include <stdlib.h>
    int *myarray;
    myarray = malloc(10 * sizeof(*myarray));
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    19

    Talking Thanks

    That was quick and really useful.

    Best,

    Tor

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  2. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  3. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  4. Array Program
    By emmx in forum C Programming
    Replies: 3
    Last Post: 08-31-2003, 12:44 AM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM