Click here to Skip to main content
15,885,365 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How can handle this exception? Pin
Alain Rist17-Nov-10 0:05
Alain Rist17-Nov-10 0:05 
GeneralRe: How can handle this exception? Pin
Cedric Moonen16-Nov-10 23:41
Cedric Moonen16-Nov-10 23:41 
GeneralRe: How can handle this exception? Pin
Alain Rist17-Nov-10 0:11
Alain Rist17-Nov-10 0:11 
GeneralRe: How can handle this exception? Pin
Le@rner17-Nov-10 0:35
Le@rner17-Nov-10 0:35 
GeneralRe: How can handle this exception? Pin
Alain Rist17-Nov-10 1:29
Alain Rist17-Nov-10 1:29 
QuestionRe: How can handle this exception? Pin
David Crow17-Nov-10 3:19
David Crow17-Nov-10 3:19 
Questionbuffer filled with trash [modified] Pin
ALLERSLIT16-Nov-10 13:22
ALLERSLIT16-Nov-10 13:22 
AnswerRe: buffer filled with trash Pin
Stephen Hewitt16-Nov-10 17:35
Stephen Hewitt16-Nov-10 17:35 
The documentation for recv[^] shows the prototype looks something like this:
int recv(
  __in   SOCKET s,
  __out  char *buf,
  __in   int len,
  __in   int flags
);

 
It describes the return value like this:
If no error occurs, recv returns the number of bytes received and the buffer pointed to by the buf parameter will contain this data received. If the connection has been gracefully closed, the return value is zero.
 
Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.

 
So what you have to do is add a NULL terminator and where you add it depends on how much data you recieved:
char buffer[250];
char hello[] = "hello?\n";
send(sock, hello, sizeof(hello), 0);
int res = recv(sock, buffer, sizeof(buffer)-1, 0); // -1 so we'll always have room for NULL terminator.
if (res != SOCKET_ERROR)
{
    buffer[res] = 0; // NULL terminate.
    cout << buffer << endl;
}
cin.get();

 
Steve

GeneralRe: buffer filled with trash Pin
Richard MacCutchan16-Nov-10 21:22
mveRichard MacCutchan16-Nov-10 21:22 
QuestionAccessing vector in another class?? Pin
AmbiguousName16-Nov-10 0:53
AmbiguousName16-Nov-10 0:53 
AnswerRe: Accessing vector in another class?? Pin
Chris Losinger16-Nov-10 1:37
professionalChris Losinger16-Nov-10 1:37 
AnswerRe: Accessing vector in another class?? Pin
Richard MacCutchan16-Nov-10 1:40
mveRichard MacCutchan16-Nov-10 1:40 
GeneralRe: Accessing vector in another class?? Pin
AmbiguousName16-Nov-10 2:14
AmbiguousName16-Nov-10 2:14 
QuestionCan i use Property Page as a dialog Box? Pin
Le@rner15-Nov-10 20:11
Le@rner15-Nov-10 20:11 
AnswerRe: Can i use Property Page as a dialog Box? Pin
Cedric Moonen15-Nov-10 20:33
Cedric Moonen15-Nov-10 20:33 
GeneralRe: Can i use Property Page as a dialog Box? Pin
Le@rner15-Nov-10 20:49
Le@rner15-Nov-10 20:49 
GeneralRe: Can i use Property Page as a dialog Box? Pin
Cool_Dev15-Nov-10 21:27
Cool_Dev15-Nov-10 21:27 
GeneralRe: Can i use Property Page as a dialog Box? Pin
Le@rner15-Nov-10 23:09
Le@rner15-Nov-10 23:09 
GeneralRe: Can i use Property Page as a dialog Box? Pin
Cool_Dev15-Nov-10 23:30
Cool_Dev15-Nov-10 23:30 
AnswerRe: Can i use Property Page as a dialog Box? Pin
Alain Rist16-Nov-10 5:21
Alain Rist16-Nov-10 5:21 
AnswerRe: Can i use Property Page as a dialog Box? Pin
David Crow16-Nov-10 3:55
David Crow16-Nov-10 3:55 
QuestionHow can use it in List Ctrl? Pin
Le@rner15-Nov-10 18:10
Le@rner15-Nov-10 18:10 
AnswerRe: How can use it in List Ctrl? Pin
Cool_Dev15-Nov-10 21:34
Cool_Dev15-Nov-10 21:34 
GeneralRe: How can use it in List Ctrl? Pin
Le@rner15-Nov-10 21:38
Le@rner15-Nov-10 21:38 
GeneralRe: How can use it in List Ctrl? Pin
Cool_Dev15-Nov-10 22:23
Cool_Dev15-Nov-10 22:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.