-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
99 lines (84 loc) · 2.05 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
///**********************************Mini Projet JEU Pendu*******************************************
int piocherMot(char *motPioche);
int existe(char mot[],char c);
char readchar();
char lirecarac(); //we always declare it before the main execution at least if you write the function later than the code source
void change(char mot[],char *m,char c);
void remplir(char *m,int n)
{
int i;
for(i = 0;i<n;i++)
m[i] = '*';
m[i] = '\0';
// m[i] = '\0';// in order to close the string
}
void jeu(char mot[],char *m)
{
char c = 0;
int t;
t = 10;
do{
printf("Donner un caractére adéquat il vous reste %d chances:\n",t);
c = lirecarac();
if(existe(mot,c)!= -1) //our existe function return the place of the char
{
change(mot,m,c);
printf("\n*********ALLEZ*******\n");
puts(m);
}else{
t--;
}
}while(existe(m,'*')!= -1 && t>0 );
if(t>0)
{
printf("\nVous avez gagnés le jeu haha\n ");
printf("\n ***********eh ben FELICITATION *******************\n ");
}
else
printf("\nVous avez perdu le jeu\n");
// printf("\n ")
}
char lirecarac()
{
char c = 0;
do{
c = getchar();
c = toupper(c);
}while( c == '\n'); //there is a one-line code that can do that, super intuitive
//strlen(c)<0 ||
return c;
}
void change(char mot[],char *m,char c)
{
for(int i = 0;mot[i];i++)
if(mot[i] == c)
m[i] = c;
}
int existe(char mot[],char c)
{
int i;
i = 0;
do{
if(mot[i] == c)
return i;
i++;
}while(mot[i]);
return -1;
}
int main()
{
char *ms,mot[100];
int tailleMot = 0;
if (!piocherMot(mot))
exit(0);
tailleMot = strlen(mot);
ms = (char *)malloc(tailleMot*sizeof(char));
remplir(ms,tailleMot);
printf("\n************************ALLEZ LE JEU À COMMENCÉ************************** \n");
jeu(mot,ms);
exit(0);
}