"mr_gees100_peas" <[EMAIL PROTECTED]> wrote:
>
>    I have the following string arrays.
> 
> char *arr1[] = {"john", "paul", "ringo"};
> char *arr2[] = {"apple", "oranges"};
> 
> char *arr3[] = {*arr1, *arr2};
> 
> What I want to do is access the content of arrays 1 and 2 inside
> of array 3.

Why? What's the real problem?

> How do I go about this? And no I can't use a two dimensional
> array.

Why not? Homework? If so then what is your code so far?
If this is not homework, then please elaborate on what it is
you are trying to do, and why _you_ think you can't use a
two dimensional array.

If you want to create a combined copy of two arrays in a third
array, then you can do something like...

  #include <stdio.h>
  #include <string.h>
  
  #define countof(x) (sizeof(x)/sizeof*(x))
  
  int main(void)
  {
    size_t i;
    char *arr1[] = {"john", "paul", "ringo"};
    char *arr2[] = {"apple", "oranges"};
    char *arr3[countof(arr1) + countof(arr2)];
  
    memcpy(arr3,                 arr1, sizeof arr1);
    memcpy(arr3 + countof(arr1), arr2, sizeof arr2);
  
    for (i = 0; i < countof(arr3); i++)
      puts(arr3[i]);
  
    return 0;
  }

Alternatively, you can use macros for your initialisors...

  #include <stdio.h>
  
  #define countof(x) (sizeof(x)/sizeof*(x))
  
  #define ARR1  "john", "paul", "ringo"
  #define ARR2  "apple", "oranges"
  
  int main(void)
  {
    size_t i;
    char *arr1[] = { ARR1 };
    char *arr2[] = { ARR2 };
    char *arr3[] = { ARR1, ARR2 };
  
    puts("arr1:");
    for (i = 0; i < countof(arr1); i++)
      puts(arr1[i]);
  
    puts("\narr2:");
    for (i = 0; i < countof(arr2); i++)
      puts(arr2[i]);
  
    puts("\narr3:");
    for (i = 0; i < countof(arr3); i++)
      puts(arr3[i]);
  
    return 0;
  }

-- 
Peter

Reply via email to