Concating byte[] and char[]

Snake's Avatar, Join Date: Jan 2010
Newbie Member
Hi there!
Iam writing a piece of code that will send file (using Wininet) to PHP script for uploading.
Headers with boundary, filename and other stuff stored as char[]. But file content that i must send to script is in byte array. How do i concat chars and bytes array? Binary data will be particullary cut (cause of 00's). Also, is there a function to figure the byte array length?
Thanks =)
0
Gene Poole's Avatar, Join Date: Nov 2009
Contributor
There is no "byte" type in C/C++ Some compilers and/or platform SDKs define or typedef it to "unsigned char" Casting your char array to "unsigned char *" should be OK in most cases.

There's no way to get byte array length except to keep track of it with an additional variable, (or use a std container like vector<> ). There is no NULL terminator like there is for a C string (char array).
0
Snake's Avatar, Join Date: Jan 2010
Newbie Member
Thnx for reply!
iam using c along with winapi and i need to concat byte and char strings. But i can't concat them with C string functions, cause when i do it byte buffer is being cut to null-terminant. So what should i do?
Sorry for my lameness =)
0
Gene Poole's Avatar, Join Date: Nov 2009
Contributor
Typically, you'd use memcpy(). It takes an additional parameter that tells it how many bytes to copy.

Code:
  //three unequal length buffers
  unsigned char buf1[26];
  size_t buf1len=26;

  unsigned char buf2[114];
  size_t buf2len=114;

  unsigned char buf3[54];
  size_t buf3len=54;

  //fill buffers, etc.

  unsigned char copybuf[500];  //or could be allocated with malloc or new

  memcpy(copybuf,buf1,buf1len);
  memcpy(copybuf+buf1len,buf2,buf2len);
  memcpy(copybuf+buf1len+buf2len,buf3,buf3len);
Snake like this
0
Snake's Avatar, Join Date: Jan 2010
Newbie Member
much appreciate =)