Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Concating byte[] and char[] (http://www.go4expert.com/forums/concating-byte-char-t20766/)

Snake 26Jan2010 14:46

Concating byte[] and char[]
 
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 =)

Gene Poole 26Jan2010 21:52

Re: Concating byte[] and char[]
 
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).

Snake 26Jan2010 23:24

Re: Concating byte[] and char[]
 
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 =)

Gene Poole 27Jan2010 00:27

Re: Concating byte[] and char[]
 
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 27Jan2010 07:59

Re: Concating byte[] and char[]
 
much appreciate =)


All times are GMT +5.5. The time now is 13:36.