.::DoX::. escribió:
En tu función no agregas el caracter nulo al final de la cadena por lo que puede presentar fallas.
Imposible que ocurra, debido al memset() y que el algoritmo solo toca los caracteres nunca toca el ultimo (Solo menset lo toca).
Por otro lado:
* No hay nesesidad de usar memset... por logica se le van a setear a TODOS los valores.
* Personalmente prefiero que las funciones trabajen sin que ellas creen memoria (para eso mejor uso las clases).
Código: Seleccionar todo
char* reverse(char* szChars, size_t iSize) {
size_t i = 0x0;
if (iSize > 1 && szChars != NULL)
for (;i < --iSize; i++) {
szChars[i] ^= szChars[iSize];
szChars[iSize] ^= szChars[i];
szChars[i] ^= szChars[iSize];
}
return szChars;
}
inline char* strrev(char *szStr)
{
return reverse(szStr, strlen(szStr));
}
int main(int argc, char * argv[])
{
char szStr[] = "BlackZeroX";
fprintf(stdout,"%s\n",strrev(szStr));
return EXIT_SUCCESS;
}
Dulces Lunas1¡.
Web: http://infrangelux.sytes.net/
ScanX: http://ScanX.sytes.net/
FileX: http://FileX.sytes.net/
Blog: http://BlogX.sytes.net/
The Dark Shadow is my passion.
El infierno es mi Hogar, mi novia es Lilith y el metal mi religion