-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutilscont1.c
More file actions
89 lines (80 loc) · 2.07 KB
/
utilscont1.c
File metadata and controls
89 lines (80 loc) · 2.07 KB
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
/* ************************************************************************** */
/* */
/* :::::::: */
/* utilscont1.c :+: :+: */
/* +:+ */
/* By: cstaats <cstaats@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2022/11/08 12:40:44 by cstaats #+# #+# */
/* Updated: 2022/11/08 13:38:50 by cstaats ######## odam.nl */
/* */
/* ************************************************************************** */
#include "so_long.h"
char keystrokes(char **map, mlx_key_data_t keydata)
{
char store;
if (keydata.action != MLX_PRESS)
return ('\0');
if (keydata.key == MLX_KEY_UP)
store = whereami(map, 0, -1);
if (keydata.key == MLX_KEY_DOWN)
store = whereami(map, 0, 1);
if (keydata.key == MLX_KEY_LEFT)
store = whereami(map, -1, 0);
if (keydata.key == MLX_KEY_RIGHT)
store = whereami(map, 1, 0);
if (keydata.key == MLX_KEY_ESCAPE)
exit(EXIT_SUCCESS);
return (store);
}
static int ft_mem(long int store)
{
int len;
len = 0;
if (store == 0)
len = 1;
else if (store < 0)
{
len = 1;
store = -store;
}
while (store)
{
store /= 10;
len++;
}
return (len);
}
char *ft_itoa(int n)
{
char *str;
int len;
if (n == INT_MIN)
return (ft_strdup("-2147483648"));
len = ft_mem(n);
str = ft_calloc((len + 1), sizeof(char));
if (str == NULL)
exit(EXIT_FAILURE);
if (n < 0)
{
str[0] = '-';
n = -n;
}
while (n > 9)
{
str[len - 1] = n % 10 + '0';
n /= 10;
len--;
}
str[len - 1] = n % 10 + '0';
return (str);
}
void *ft_calloc(size_t nitems, size_t size)
{
void *pnt;
pnt = malloc(nitems * size);
if (pnt == NULL)
return (NULL);
ft_bzero(pnt, (nitems * size));
return (pnt);
}