Ok guys, I'm nearly done with what I hope will be enough for a framework for a simple chat application now (the idea is to bypass MFC by using SDL (I have bookmarked the article that was posted about using SDL to create windows here earlier)). Anyway, I'm still a bit confused about this char stuff. :( Now I have a buffer declared like so:
and a function implemented like so:
char RecvData(int nret, int socket){ //char buffer[256]; // On the stack char *buffer = new char[256]; // or on the heap nret = recv(socket, buffer, 256, // Complete size of buffer 0); delete [] buffer;// Manipulate buffer, then delete if and only if // buffer was allocated on heap if (nret == SOCKET_ERROR) { // Get a specific code // Handle accordingly MessageBox(NULL, (char*)nret, "RecvData() error!", MB_OK); } else { return buffer[256]; }}
I try to call this function by doing:
// Send and receive from the client, and finally, buffer = RecvData(nret, theClient); closesocket(theClient); closesocket(listeningSocket);
That gives me this error:
--------------------Configuration: Listening socket - Win32 Debug--------------------Compiling...main.cppC:\Programs\C++\WinSock\Listening socket\main.cpp(93) : error C2440: '=' : cannot convert from 'char' to 'char *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style castError executing cl.exe.Listening socket.exe - 1 error(s), 0 warning(s)
Any ideas? :(
Edit: That is fixed now, but it seems that the return in the function only returns the last element. How do I do this, and how would that require the buffer outside the function to be declared?