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 =)
|
Contributor
|
|
| 26Jan2010,21:52 | #2 |
|
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). |
|
Newbie Member
|
|
| 26Jan2010,23:24 | #3 |
|
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 =) |
|
Contributor
|
|
| 27Jan2010,00:27 | #4 |
|
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
|
|
Newbie Member
|
|
| 27Jan2010,07:59 | #5 |
|
much appreciate =)
|
