-
Notifications
You must be signed in to change notification settings - Fork 0
/
nombre_cacher.c
61 lines (54 loc) · 1.31 KB
/
nombre_cacher.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
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include <glib.h>
#include <ctype.h>
#include<time.h>
void victoire(int val ) {
char *cmd = NULL;
if (system("ponysay --help > /dev/null") == 0) {
cmd = g_strdup_printf ("ponysay BRAVO VOUS AVEZ TROUVE LE NOMBRE MAGIQUE: %d", val);
system(cmd);
g_free(cmd);
} else if (system("cowsay --help > /dev/null") == 0) {
cmd = g_strdup_printf ("cowsay BRAVO VOUS AVEZ TROUVE LE NOMBRE MAGIQUE: %d", val);
system(cmd);
g_free(cmd);
}
}
bool verifier(int nb, int magic) {
bool check = false;
char *msg = NULL;
if (system("ponysay --help > /dev/null") || system("sl --help > /dev/null"))
return false;
if (nb == magic) {
victoire(magic);
check = true;
} else if (nb < magic) {
msg = g_strdup_printf ("\n\nponysay -f derpysad Plus grand que %d\n", nb);
system(msg);
system("sl");
g_free(msg);
check = false;
} else if (nb > magic) {
msg = g_strdup_printf ("\n\nponysay -f derpysad Plus petit que %d\n", nb);
system(msg);
g_free(msg);
check = false;
}
return check;
}
int main() {
int magic = 0;
int nb = 'c';
bool is_true = false;
srand(time(NULL));
magic = ((rand() % 100) + 1);
system("clear");
while(!is_true) {
printf("\nQuel est le nombre magique: ");
scanf("%d", &nb);
is_true = verifier(nb, magic);
}
return 0;
}