this function in my TCP/IP wrapper class reads from the socket into the char pointer bufm byte at a time until it reads the string "end". I can verify that it actually does this using printf right before the return 0...
(continued below)
Code:
int TcpIp::readUntil(char *buf, int bufsiz, char *end)
{
char tbuf[1];
int br = 0;
tbuf[1] = '\0';
buf[0] = '\0';
while (recv(connection, tbuf, 1, 0) != SOCKET_ERROR)
{
strcat(buf, tbuf);
if (strstr(buf,end))
{
return 0;
}
br ++;
if (br == bufsiz)
{
return 1;
}
}
return 2;
}
but when i call this functon from main:
Code:
TcpIp connection;
char buffer[256];
if (!connection.conn("127.0.0.1",555))
{
if (!connection.readUntil(buffer, 256, "\n\n"))
{
cout << buffer;
}
}
delete &connection;
the buffer is filled with garbage, even if the function itself proves the pointer has the received string in it.
Bloody hell.