-
Notifications
You must be signed in to change notification settings - Fork 0
/
print.c
118 lines (107 loc) · 2.09 KB
/
print.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jschotte <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/12/10 12:54:27 by jschotte #+# #+# */
/* Updated: 2015/12/18 15:45:33 by jschotte ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
char *ft_letter(char *str, char c)
{
int i;
i = 0;
while (str[i])
{
if (str[i] == '#')
str[i] = c;
i++;
}
return (str);
}
char *ft_fillmap(char *map, int nb)
{
int i;
int j;
i = 0;
j = 0;
while (i < nb * nb + nb)
{
map[i] = '.';
i++;
j++;
if (j == nb)
{
map[i] = '\n';
j = 0;
i++;
}
}
map[i] = '\0';
return (map);
}
void ft_printmap(char *map)
{
int i;
i = 0;
while (map[i])
{
ft_putchar(map[i]);
i++;
}
}
char *ft_canplace(char *map, char *piece, int index, int nb)
{
int i;
size_t k;
int line;
i = 0;
k = index;
line = 0;
while (piece[i])
{
if ((map[k] == '.' || (ft_isalpha(map[k]) && piece[i] == '.')))
{
i++;
k++;
if (piece[i] == '\n')
{
line++;
i++;
k = index + (nb + 1) * line;
}
}
else
return (0);
}
return (map);
}
char *ft_place(char *map, char *piece, int index, int nb)
{
int i;
int k;
int line;
i = 0;
k = index;
line = 0;
while (piece[i] && map[k])
{
if (map[k] == '.' || (ft_isalpha(map[k]) && piece[i] == '.'))
{
if (map[k] == '.')
map[k] = piece[i];
i++;
k++;
if (piece[i] == '\n')
{
line++;
i++;
k = index + (nb + 1) * line;
}
}
}
return (map);
}