0

I have two arrays of pointers, that is,

char *a[3]= {"man","dog","cat"};
char *b[3]= {"job","rain","sleep"};

I want to separate the three strings of both above into three different characters arrays and then I want to concatenate the string from *b[] to the end of string from *a[].

How can I accomplish this? I don't want to print the separated strings.

5
  • 4
    This question is off topic on Programmers. It would best be asked on Stack Overflow, however, the question doesn't meet their minimum requirements. Please read the Stack Overflow question checklist and edit your question to make it suitable for migration. Commented Dec 25, 2013 at 11:15
  • There is a need to provide a new array because expansion of the array can not be. Commented Dec 25, 2013 at 14:52
  • "... I want to separate the three strings of both above ..." there are six strings. Commented Dec 25, 2013 at 16:20
  • For one thing, it is illegal to use char * to point to string literals. You need const char *. Commented Dec 26, 2013 at 1:34
  • @Siyuan Ren: It is not illegal to use char * to point to string literals. Read the C Standard: For character string literals, the array elements have type charIf the program attempts to modify such an array, the behavior is undefined. Commented Nov 4, 2016 at 15:00

1 Answer 1

1

If I have understood correctly you want the following

char s[3][10];

for ( size_t i = 0; i < 3; i++ )
{
   strcpy( s[i], a[i] );
   strcat( s[i], " " );
   strcat( s[i], b[i] );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.