-
-
Save parzibyte/72e3e579c6f0cab8c3707f2408d8eb10 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <ctype.h> | |
#define MAXIMA_LONGITUD_CADENA 1000 | |
int contieneAlMenosUnNumero(char cadena[MAXIMA_LONGITUD_CADENA]) | |
{ | |
int indice = 0; | |
while (cadena[indice] != '\0') | |
{ | |
char actual = cadena[indice]; | |
if (isdigit(actual)) | |
{ | |
return 1; | |
} | |
indice++; | |
} | |
return 0; | |
} | |
int contieneAlMenosUnaLetra(char cadena[MAXIMA_LONGITUD_CADENA]) | |
{ | |
int indice = 0; | |
while (cadena[indice] != '\0') | |
{ | |
char actual = cadena[indice]; | |
if (isalpha(actual)) | |
{ | |
return 1; | |
} | |
indice++; | |
} | |
return 0; | |
} | |
int esPalabraSecretaValida(char palabraSecreta[MAXIMA_LONGITUD_CADENA]) | |
{ | |
if (strlen(palabraSecreta) < 8 || strlen(palabraSecreta) > 12) | |
{ | |
return 0; | |
} | |
if (!contieneAlMenosUnaLetra(palabraSecreta) || !contieneAlMenosUnNumero(palabraSecreta)) | |
{ | |
return 0; | |
} | |
return 1; | |
} | |
int main() | |
{ | |
printf("%d\n", esPalabraSecretaValida("hola")); // 0 | |
printf("%d\n", esPalabraSecretaValida("hola12")); // 0 | |
printf("%d\n", esPalabraSecretaValida("hola1234")); // 1 | |
printf("%d\n", esPalabraSecretaValida("hunter2")); // 0 | |
printf("%d\n", esPalabraSecretaValida("123")); // 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment