En el lado del servidor detectar cuando se cierre la conexión.
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes MenúCita de: SXF en 6 Marzo 2012, 00:41 AMEso es C++
Buenas, pues para pasar un rato divertido propongo un reto: Crear un codigo que nos diga si un número ES primo lo mas corto y eficiente posible, vale cualquier lenguaje;
Empiezo con el mio:
en c:
int esPrimo(int n){
for (int i=2; i<n; i++) if(n%i==0) return 0;
return 1;
}
try{
buffer=servidor->recibirBuffer();
}catch(...){
break;
}
string server::recibirBuffer()
{
string rtn;
char buffer[MAX_BUFFER+1];
DWORD bytes;
fd_set ss;
timeval touts;
FD_ZERO(&ss);
FD_SET(cnn,&ss);
touts.tv_sec = 5;
touts.tv_usec = 0;
if(select(0,&ss,NULL,NULL,&touts) == SOCKET_ERROR || (bytes=recv(cnn,buffer,MAX_BUFFER,0))<=0)
throw 1;
if(bytes>0)
{
buffer[bytes]='\0';
rtn = buffer;
}
return rtn;
}
felino(){};
felino::felino(char* comida, int año, char* lugar, char* raz, char* circ):mamifero( comida, año, lugar)
{
raza = new char[strlen(raz)];
circo = new char[strlen(circ)];
raza = raz;
circo = circ;
}
Cita de: cplusplus.comchar * strtok ( char * str, const char * delimiters );
Split string into tokens
A sequence of calls to this function split str into tokens, which are sequences of contiguous characters separated by any of the characters that are part of delimiters.
On a first call, the function expects a C string as argument for str, whose first character is used as the starting location to scan for tokens. In subsequent calls, the function expects a null pointer and uses the position right after the end of last token as the new starting location for scanning.
To determine the beginning and the end of a token, the function first scans from the starting location for the first character not contained in delimiters (which becomes the beginning of the token). And then scans starting from this beginning of the token for the first character contained in delimiters, which becomes the end of the token.
This end of the token is automatically replaced by a null-character by the function, and the beginning of the token is returned by the function.
Once the terminating null character of str has been found in a call to strtok, all subsequent calls to this function with a null pointer as the first argument return a null pointer.
#include <stdio.h>
#include <string.h>
int main()
{
char cadena[] = "Hola\ta todos que\tal estais?";
char * ptr_token;
ptr_token = strtok(cadena,"\t ");
while(ptr_token)
{
printf("%s\n",ptr_token);
ptr_token = strtok(NULL,"\t ");
}
return 0;
}
Cita de: RHL en 17 Febrero 2012, 09:12 AM
Que yo sepa todos las clases tienen un constructor por defecto, sino definimos uno el compilador crea uno por defecto