Basquet, Fronton... me terminan las manos muy rojas.

Dulces Lunas!¡.

Dulces Lunas!¡.
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ú
#include <stdlib.h>
#include <stdio.h> //<stdio.h>
typedef
struct Matrix
{
float **lpData;
unsigned int uiRows;
unsigned int uiCols;
}
MATRIX, *LPMATRIX;
LPMATRIX createMatrix(unsigned int uiRows, unsigned int uiCols)
{
LPMATRIX lpRet = (LPMATRIX)malloc(sizeof(MATRIX));
int i = 0;
lpRet->uiCols = uiCols;
lpRet->uiRows = uiRows;
lpRet->lpData = (float**)malloc(sizeof(float*) * lpRet->uiRows);
for (i = 0; i < lpRet->uiRows; i++)
lpRet->lpData[i] = (float*)malloc(sizeof(float) * lpRet->uiCols);
return lpRet;
}
void freeMatrix(LPMATRIX lpMatrix)
{
int i = 0;
if (!lpMatrix) return;
for (i = 0; i < lpMatrix->uiRows; i++)
free(lpMatrix->lpData[i]);
free(lpMatrix->lpData);
free(lpMatrix);
}
void showMatrix(LPMATRIX lpMatrix)
{
int i = 0,
j = 0;
if (!(lpMatrix || lpMatrix->lpData)) return;
for (i = 0; i < lpMatrix->uiRows; i++)
{
if (lpMatrix->lpData[i])
{
for (j = 0; j < lpMatrix->uiCols; j++)
printf("\t%f", lpMatrix->lpData[i][j]);
printf("\n");
}
}
}
int getDeterminant(LPMATRIX lpMatrix, float* lpOutDeterminant)
// Retorna 0 si todo a ido bien, de lo contrario retorna un numero distinto de 0
{
float fRet = 0.0f,
fProduct = 0.0f;
unsigned int i = 0,
j = 0;
if (!(lpMatrix || lpMatrix->lpData) || (lpMatrix->uiRows < 2) || (lpMatrix->uiCols < 2) || (lpMatrix->uiRows != lpMatrix->uiCols)) return -1;
if (lpMatrix->uiCols == 2)
{
if (!(lpMatrix->lpData[0] && lpMatrix->lpData[1])) return -1;
fRet = lpMatrix->lpData[0][0] * lpMatrix->lpData[1][1] - lpMatrix->lpData[1][0] * lpMatrix->lpData[0][1];
} else {
for (i = 0; i < lpMatrix->uiRows; i++)
{
if (!lpMatrix->lpData[i]) return -1;
// Multiplicacion de valores verticales de izquierda a derecha...
fProduct = 1.0f;
for (j = 0; j < lpMatrix->uiCols; j++)
fProduct *= lpMatrix->lpData[(i + j) % lpMatrix->uiCols][j];
fRet += fProduct;
// Multiplicacion de valores verticales de derecha a izquierda...
fProduct = 1.0f;
for (j = 0; j < lpMatrix->uiCols; j++)
fProduct *= lpMatrix->lpData[(lpMatrix->uiCols - 1) - ((i + j) % lpMatrix->uiCols)][j];
fRet -= fProduct;
}
}
if (lpOutDeterminant)
*lpOutDeterminant = fRet;
return 0;
}
int main()
{
LPMATRIX lpMatrix = createMatrix(3,3);
float fDeterminant = 0.0;
int i = 0,
j = 0;
for (i = 0; i < lpMatrix->uiRows; i++)
{
for (j = 0; j < lpMatrix->uiCols; j++)
{
printf("[%d][%d] = ",i, j); fflush(stdout);
scanf("%f", &lpMatrix->lpData[i][j]);
}
}
fflush(stdout);
showMatrix(lpMatrix);
if (getDeterminant(lpMatrix, &fDeterminant) == 0)
printf("Determinante = %f\n", fDeterminant);
freeMatrix(lpMatrix);
getchar();
return EXIT_SUCCESS;
}
bool CSockClient::connect(const char* szIP, unsigned short int iPort)
{
hostent* lpHosten = NULL;
if (this->iState != SCKCLOSED )
{
this->setError();
return false;
}
if (szIP == NULL || iPort == 0)
return false;
this->iRemotePort = iPort;
this->sRemoteHost = szIP;
memset(&this->udtSockAddrIn, 0, sizeof(sockaddr_in));
this->udtSockAddrIn.sin_family = AF_INET;
this->udtSockAddrIn.sin_port = htons(iPort);
this->iState = SCKOPEN;
if (this->udtSockAddrIn.sin_port == INVALID_SOCKET)
{
this->setError();
return false;
}
lpHosten = ::gethostbyname(this->sRemoteHost.c_str());
if (lpHosten == NULL)
{
this->setError();
return false;
}
this->udtSockAddrIn.sin_addr.s_addr = *((unsigned long*)lpHosten->h_addr_list[0]);
// memcpy(&uiRet, hHost->h_addr_list[0], hHost->h_length);
this->sLocalHostIP.assign(inet_ntoa(this->udtSockAddrIn.sin_addr));
if (this->udtSockAddrIn.sin_addr.s_addr == INADDR_NONE)
{
this->setError();
return false;
}
this->mySock = ::socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (this->mySock == INVALID_SOCKET)
{
this->setError();
return false;
}
if (!this->getSocketOpt())
return false;
//Creamos el hilo para resivir los datos de este Socket.
if (pthread_create(&this->threadConnect, NULL, myCallConnect, this))
{
if (this->pEventError != NULL) //Evento
this->pEventError(this);
if (this->mySock != INVALID_SOCKET )
closesocket(this->mySock);
this->mySock = INVALID_SOCKET;
this->setError();
return false;
}
pthread_detach(this->threadConnect); // No guardar Returns del hilo...
return true;
}
#include <stdlib.h>
#include <stdio.h> //<stdio.h>
#include <string.h> //<stdio.h>
const int BUFFER = 250;
char* SubExtractFrontBegin(const char* szIn, const char caracter);
char* ReadInput(FILE* FileSrc);
int main()
{
char* szCadena = NULL;
char* szSubCadena = NULL;
char Caracter = 0;
puts("Ingresa la cadena:\n");
szCadena = ReadInput(stdin);
puts("Ingrese caracter a buscar:\n");
Caracter = getchar();
szSubCadena = SubExtractFrontBegin(szCadena, Caracter);
printf("Subcadena:%s\n", szSubCadena);
free(szCadena);
free(szSubCadena);
getchar();
return EXIT_SUCCESS;
}
char* SubExtractFrontBegin(const char* szIn, const char caracter)
{
char szDelim[2] = {caracter, '\0'};
char* szPos = strstr(szIn, szDelim);
char* szRet = NULL;
if (szPos == NULL) return szRet;
szRet = (char*)malloc(((size_t)szPos) - ((size_t)szIn) + 1);
memcpy(szRet, szIn, (size_t)szPos - (size_t)szIn);
return szRet;
}
char* ReadInput(FILE* FileSrc)
{
char c = 0;
char *szRet = NULL;
size_t size = 0;
while(++size)
{
szRet = (char*)realloc(szRet, size);
fread(&c, 1, 1, FileSrc);
if (c == '\n')
break; // exit while(1)
szRet[size - 1] = c;
}
return szRet;
}
Cita de: Xkipper en 5 Febrero 2012, 05:57 AM
Leí el documento intente crear algo y no hubo resultado. El documento ya esta hecho para personas que saben, no hay ejemplos claros para novatos.