When I use strncat, I get strange characters appended to my string, although the string buffer is only 8 bytes in size which is verified and its told to only copy 8 characters (which I've even tried hardcoding). Where are they coming from?
Code:
RecvMsg(buf, client, sizeof(buf)); //Recieve our packet
char p[((uint8(buf[0])<<8)|uint8(buf[1]))]; //Allocate just enough to hold the playername
memset(p, 0, sizeof(p));
std::string playerName = strncpy(p, buf + 2, sizeof(p));
Then std::cout << "Playername: " << p << std::endl;
or std::cout << "Playername:" << playerName << std::endl;
or printf(p);
or printf(playerName.c_str());
all result in:
MasterCQ��t�O��t�