Thread: appending to an array

  1. #1
    Registered User
    Join Date
    Feb 2004

    appending to an array

    I am going to sound really thick, so sorry!!

    I have an array and I have filled it with elements (as in E in the example below) I would like then to add that array to another array and just add an element at the beginning or the end and would like to deal with the array as the whole instead of using a for loop to deal with each individual element in the array.

    Is there a way I have tried F={23,E} but obviously this doesn't work. Any help would be great


    int i;
    int E[9];
    int Fup[10];
    int Fdown[10];


    Fup= {E,23};

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    C doesn't support such a thing. You'll need to use a function to do it for you. Conveniently enough, memcpy will do this for you:
    #include <stdio.h>
    #include <string.h>
      int a[10] = {1,2,3,4,5};
      int b[] = {6,7,8,9,10};
      int i;
      memcpy(a + 5, b, 5 * sizeof(int));
      for (i = 0; i < 10; i++) {
        printf("%d\n", a[i]);
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 10:33 AM
  3. Replies: 7
    Last Post: 11-25-2008, 01:50 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. Array Program
    By emmx in forum C Programming
    Replies: 3
    Last Post: 08-31-2003, 12:44 AM