Store an array to an integer array??

Discussion in 'C Programming' started by rhitz1218@gmail.com, Dec 11, 2006.

  1. Guest

    Hi all:

    Is it possible to store an integer array to another integer array?
    Or should I use an array of pointers that will point to a particular
    array?

    Thanks for the help.
    , Dec 11, 2006
    #1
    1. Advertising

  2. Ben Pfaff Guest

    writes:

    > Is it possible to store an integer array to another integer array?


    Do you mean an array of integer arrays? Just like this:
    int x[2][3];

    > Or should I use an array of pointers that will point to a particular
    > array?


    What are you trying to do?
    --
    int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.\
    \n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
    );while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p\
    );}return 0;}
    Ben Pfaff, Dec 11, 2006
    #2
    1. Advertising

  3. Guest


    > What are you trying to do?
    > --


    For example, I have 4 integer arrays with size 4:

    my_array1, my_array2, my_array3, my_array4..
    each array will contain 4 integers..

    Now I would like to store these 4 arrays in anothe location because I
    would like to print them later on.. Can I store them in anothe array?
    or should I create an array that points to them?


    thanks..
    , Dec 11, 2006
    #3
  4. santosh Guest

    wrote:
    > Hi all:
    >
    > Is it possible to store an integer array to another integer array?


    If they're of the same type and size, then yes.

    > Or should I use an array of pointers that will point to a particular
    > array?


    Can't say unless you tell us what you're trying to do. In programming
    there're, usually, many ways to accomplish something. What is most
    suitable depends on the details of the specific program and it's
    environment.
    santosh, Dec 11, 2006
    #4
  5. santosh Guest

    wrote:
    > > What are you trying to do?
    > > --

    >
    > For example, I have 4 integer arrays with size 4:
    >
    > my_array1, my_array2, my_array3, my_array4..
    > each array will contain 4 integers..
    >
    > Now I would like to store these 4 arrays in anothe location because I
    > would like to print them later on.. Can I store them in anothe array?
    > or should I create an array that points to them?


    If your arrays are local and the code to print them will be elsewhere
    in scope then you'll need to store these arrays somewhere else, just
    pointing to them will not be enough.

    If they're dynamically allocated or declared static or global then
    holding pointers to them is sufficient.
    santosh, Dec 11, 2006
    #5
  6. Guest


    > Can't say unless you tell us what you're trying to do. In programming
    > there're, usually, many ways to accomplish something. What is most
    > suitable depends on the details of the specific program and it's
    > environment.


    I'm trying to find a "fixed point" of a number that is for ex:

    954 (high to lo) - 495 (lo to high) = 495
    then next step
    954 (high to lo) - 495 (lo to high) = 495

    from here, I can say that 495 is a fixed point, I would like to put
    this in a "storage" (array??) so I can print all the fixed points that
    I've found later..(Cause I need to check for other fixed points of
    other numbers)

    NOTE: 495 is stored in an array of size 3, I had to store each digits
    in an array to perform my sorting..

    thanks for the help..
    , Dec 11, 2006
    #6
  7. santosh Guest

    wrote:
    > > Can't say unless you tell us what you're trying to do. In programming
    > > there're, usually, many ways to accomplish something. What is most
    > > suitable depends on the details of the specific program and it's
    > > environment.

    >
    > I'm trying to find a "fixed point" of a number that is for ex:
    >
    > 954 (high to lo) - 495 (lo to high) = 495
    > then next step
    > 954 (high to lo) - 495 (lo to high) = 495
    >
    > from here, I can say that 495 is a fixed point, I would like to put
    > this in a "storage" (array??) so I can print all the fixed points that
    > I've found later..(Cause I need to check for other fixed points of
    > other numbers)
    >
    > NOTE: 495 is stored in an array of size 3, I had to store each digits
    > in an array to perform my sorting..


    See my reply to you in the other thread.
    santosh, Dec 11, 2006
    #7
  8. On 10 Dec 2006 19:07:28 -0800, wrote:

    >Hi all:
    >
    > Is it possible to store an integer array to another integer array?
    >Or should I use an array of pointers that will point to a particular
    >array?
    >


    You can always copy array elements using a loop with an assignment
    statement as long as each from_element processed by the loop has be
    assigned or initialized with a value.

    If you are referring to one dimensional arrays, then memcpy will copy
    data from one array to another as long as the number of bytes you
    specify is not larger than the size of either array. This may or may
    not be "better" than using a loop with an assignment statement.

    If the arrays are multi-dimensional with identical dimensions, memcpy
    will still work.

    If the arrays are multi-dimensional with different dimensions, memcpy
    can still be used but there may be some "boundary" issues.


    Remove del for email
    Barry Schwarz, Dec 12, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UnVkeQ==?=

    to store or not to store an image

    =?Utf-8?B?UnVkeQ==?=, Mar 29, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    618
    =?Utf-8?B?UnVkeQ==?=
    Mar 30, 2005
  2. anand_ps
    Replies:
    3
    Views:
    1,566
    Ryan Stewart
    Jan 19, 2005
  3. Replies:
    4
    Views:
    313
    Roedy Green
    Oct 1, 2005
  4. obdict

    Store a char into an integer variable

    obdict, Feb 8, 2006, in forum: C Programming
    Replies:
    12
    Views:
    533
    Mark McIntyre
    Feb 8, 2006
  5. gopesh patel
    Replies:
    5
    Views:
    2,092
    Stuart Golodetz
    Sep 16, 2010
Loading...

Share This Page