char array/strcat() problem
i'm trying to break a char array up and process it and then return the processed string. the unpack function will be at the bottom, if you don't know what its doing just by looking at the code.
PHP Code:
char buffer[1024], flag[5];
int rc = recv(engine::esock.sock, buffer, sizeof(buffer), 0);
if ((rc != -1) && (rc != 0))
{
unsigned int value = unpack(buffer[0], buffer[1]);
itoa(value, flag, 10);
char instruction[rc - 2], rebuff[rc + 3];
int i = 0;
int c = rc - 2;
while (i < c)
{
instruction[i] = buffer[i + 2];
i++;
}
switch (value)
{
case(0): // creation accept
strcat(rebuff, flag);
strcat(rebuff, instruction);
break;
}
engine::sockRcvErr = 0;
return(rebuff);
}
PHP Code:
unsigned int unpack(char byteA, char byteB)
{
return ((static_cast<unsigned int>(byteA) << 8) | byteB);
}
what the code is suppose to do is take a string turn the first two bytes of the string into a 5 digit number and make that a string. then take the rest of the string and make that into another string and then add the two of them into one string and return that string.
i know i have a switch statement with only one case. this is because there will be thousands of cases later.