-
Notifications
You must be signed in to change notification settings - Fork 0
/
allum1_2.c
94 lines (85 loc) · 1.42 KB
/
allum1_2.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
/*
** allum1_2.c for allum1 in /home/simon_w/Prog_Elem/alum1/CPE_2015_Allum1
**
** Made by Erwan Simon
** Login <simon_w@epitech.net>
**
** Started on Fri Feb 19 16:21:06 2016 Erwan Simon
** Last update Thu Feb 25 15:41:30 2016 Erwan Simon
*/
#include <stdlib.h>
#include <unistd.h>
#include "alum1.h"
void my_putchar(char c)
{
write(1, &c, 1);
}
void my_putstr(char *str)
{
int a;
a = 0;
while (str[a] != '\0')
{
my_putchar(str[a]);
a++;
}
}
int *win_or_lose(int tour, int a, int *number)
{
if (tour == 1 && a == 4)
{
my_printf("You lost, too bad..\n");
return (NULL);
}
if (tour == 2 && a == 4)
{
my_printf("I lost.. snif.. but I'll get you next time!!\n");
return (NULL);
}
if (tour == 3 && a != 4)
{
my_printf("\n");
return (number);
}
return (number);
}
int *how_many_left(char **array, int tour)
{
int y;
int x;
int *number;
int a;
y = 1;
x = 1;
a = 0;
number = malloc(sizeof(int) * 4);
while (y != 5)
{
while (x != 8)
{
if (array[y][x] == '|')
number[y - 1]++;
x++;
}
if (number[y - 1] == 0)
a++;
x = 1;
y++;
}
return (win_or_lose(tour, a, number));
}
char **remove_match(char **array, int line, int match)
{
int a;
a = 7;
while (match != 0)
{
if (array[line][a] == '|')
{
array[line][a] = ' ';
match--;
}
a--;
}
return (array);
}