-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.c
More file actions
70 lines (59 loc) · 1.27 KB
/
lib.c
File metadata and controls
70 lines (59 loc) · 1.27 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
/*
** EPITECH PROJECT, 2024
** B-MUL-100-LYN-1-1-myhunter-aurelien.demeusy
** File description:
** lib.c
*/
#include <unistd.h>
#include "include/structs.h"
#include "include/my.h"
int my_strlen(char const *str)
{
int i = 0;
while (str[i] != '\0') {
i++;
}
return i;
}
int my_putstr(char const *str)
{
int len = my_strlen(str);
write(2, str, len);
return 0;
}
char *my_strcat(char *dest, char const *src)
{
int i = 0;
int k = my_strlen(dest);
while (src[i] != '\0') {
dest[i + k] = src[i];
i++;
}
dest[i + k] = '\0';
return dest;
}
int my_strcmp(char const *s1, char const *s2)
{
int i = 0;
if (my_strlen(s1) < my_strlen(s2))
return -1;
if (my_strlen(s1) > my_strlen(s2))
return 1;
while (s1[i] != '\0' || s2[i] != '\0') {
if (s1[i] > s2[i])
return 1;
if (s2[i] > s1[i])
return -1;
i++;
}
return 0;
}
void my_snprintf(char *timer_text, int integer_part, int fractional_part)
{
char elapsed_str[20];
ulonglong_to_string(integer_part, elapsed_str);
my_strcat(timer_text, elapsed_str);
my_strcat(timer_text, ".");
ulonglong_to_string(fractional_part, elapsed_str);
my_strcat(timer_text, elapsed_str);
}