Jump to content
tom 2007

Concatenation Of Strings

Recommended Posts

Hello,

 

What is the easiest way to concat 2 strings (unsigned char*) in boost c? I don't see any operator or function that can do this in the manual?

 

Thnx

Tom

Share this post


Link to post
Share on other sites

Hi Tom,

 

strcat() is the standard C function. Look at page 76 of the latest BoostC manual and the string.h file.

 

The string functions have probably been there since K&R invented C.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

Can u give an example of how to use it?

Let's say you have 2 or 3 strings (random size and total size max 80 chars) you want to pass them as 1 big string to a function how would you do that with strncat function?

Something like:

send_data("string1"+"string2"+"string3");

 

 

Thanx

Share this post


Link to post
Share on other sites

Hi Tom,

 

The header file and any C book will reveal all.

 

char	bigbuffer[80] = "";
char	*str1 = "string 1";
char	*str2 = "string 2";
char	*str3 = "string 3";

void main()
{
strcat(bigbuffer, str1);
strcat(bigbuffer, str2);
strcat(bigbuffer, str3);

send_data(bigbuffer);

}

 

bigbuffer must be large enough to hold the largest length of string that you expect.

 

The C string library contain many primitive functions that you can build on.

 

Remember this is C and not C++ or VB.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...