Compare commits

..

7 commits
2 ... main

4 changed files with 35 additions and 4 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
.vscode .vscode
*.pdf *.pdf
main main
main.exe

12
.gitlab-ci.yml Normal file
View file

@ -0,0 +1,12 @@
image: gcc
stages:
- build
build:
stage: build
script:
- gcc main.c -o pendu
artifacts:
paths:
- pendu

View file

@ -1,4 +1,6 @@
# Pendu # Pendu
Mon premier pendu tout language confondu, s'il y a des approximations tu peux faire une PR 😀 Mon premier pendu tout language confondu, s'il y a des approximations tu peux faire une PR 😀
Pour lancer le pendu : `git clone https://github.com/Mylloon/pendu-C.git && cd pendu-C && gcc main.c -o main && ./main listeMots.txt` devrait fonctionner. Pour lancer le pendu : `git clone https://gitlab.com/Mylloon/penduEnC.git && cd penduEnC && gcc main.c -o main && ./main listeMots.txt` devrait fonctionner.
Tu peux aussi télécharger l'artéfact de la [dernière pipeline](https://gitlab.com/Mylloon/penduEnC/-/pipelines/).

22
main.c
View file

@ -48,15 +48,31 @@ char * recuperationMot(const char file[]) { // pour récupérer un mot aléaotoi
return mot; return mot;
} }
int caractereSpecial(char lettre) { // vérification que la lettre n'est pas un caractere special
if(lettre == ' ') return 1;
if(lettre == '\'') return 1;
if(lettre == '-') return 1;
return 0;
}
char * obfuscation(char mot[], int lettresValidees[], int taille) { // pour afficher les trous dans le mot char * obfuscation(char mot[], int lettresValidees[], int taille) { // pour afficher les trous dans le mot
int tailleMot = taille * 2; int tailleMotCache = taille * sizeof(char) * 2;
char * motCache = malloc(tailleMot * sizeof(char)); char * motCache = malloc(tailleMotCache); // x2 pour l'espace entre les "_"
int j = 0; int j = 0;
for(int i = 0; i < taille; i++) { for(int i = 0; i < taille; i++) {
if(lettresValidees[i] != 1) motCache[j] = '_'; else motCache[j] = mot[i]; if(lettresValidees[i] != 1) { // pas trouvé
if(caractereSpecial(mot[i]) == 0) motCache[j] = '_'; // si c'est pas un caractère spéciale
else { // si c'en est un
motCache[j] = mot[i];
lettresValidees[i] = 1;
}
} else motCache[j] = mot[i]; // trouvé
motCache[j + 1] = ' '; // on rajoute un espace entre les underscores motCache[j + 1] = ' '; // on rajoute un espace entre les underscores
j = j + 2; j = j + 2;
} }
for(int i = 0; i < longueurMot(motCache); i++)
if(i >= tailleMotCache) motCache[i] = 0;
return motCache; return motCache;
} }