Skip to content

Instantly share code, notes, and snippets.

@parzibyte

parzibyte/leer.c Secret

Created March 23, 2022 21:22
Show Gist options
  • Save parzibyte/2034c5a3a5cb3375cf23ada75370ab31 to your computer and use it in GitHub Desktop.
Save parzibyte/2034c5a3a5cb3375cf23ada75370ab31 to your computer and use it in GitHub Desktop.
void leerContrasenaSinMostrarla(char *palabraSecretaDestino)
{
int caracterLeido = 0;
char temporal[2];
while (caracterLeido != TECLA_ENTER)
{
limpiarPantalla();
printf("Ingresa tu palabra secreta: ");
enmascaraCadena(palabraSecretaDestino, strlen(palabraSecretaDestino), MASCARA);
caracterLeido = getch();
// https://parzibyte.me/blog/2019/11/02/c-char-a-string/
temporal[0] = caracterLeido;
temporal[1] = '\0';
if (caracterLeido == TECLA_BORRAR)
{
if (strlen(palabraSecretaDestino) > 0)
{
// https://parzibyte.me/blog/2022/03/23/eliminar-ultimo-caracter-cadena-c/
palabraSecretaDestino[strlen(palabraSecretaDestino) - 1] = '\0';
}
}
else if (caracterLeido != TECLA_ENTER)
{
strncat(palabraSecretaDestino, temporal, 1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment