0

I am talking about some sort of function that can combine an array of character arrays into a single string.

Would I just have to loop through the array of strings and do it manually? The string was created using strtok().

1
  • 4
    One might say there is no easy way to work with strings in C. Commented Jan 27, 2012 at 4:16

2 Answers 2

2

If you're just using standard C and the standard C library, you have to loop through and do it manually. (Of course you might use strncat in your loop.)

Sign up to request clarification or add additional context in comments.

Comments

0

If you have an array of char arrays, like this:

char foo[<num>][<len>];

...then you can convert it into a string like this:

char *bar = (char *)foo;

If your strings are NULL-terminated or smaller than len, you may have to memmove() foo[i+1] to the position of strlen(bar) for each i.

Of course, it might be easier to just iterate through the array and concatenate the strings using strcat().

Comments

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.