-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathannexe.c
More file actions
80 lines (69 loc) · 1.24 KB
/
annexe.c
File metadata and controls
80 lines (69 loc) · 1.24 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
/*
** EPITECH PROJECT, 2025
** B-PSU-200-LYN-2-1-minishell1-pierre.baud
** File description:
** annexe
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "my.h"
int my_strlen(const char *str)
{
int len = 0;
while (str[len] != '\0') {
len++;
}
return len;
}
char *my_strdup(const char *src)
{
int len = my_strlen(src);
char *dest = malloc((len + 1) * sizeof(char));
int i = 0;
if (dest == NULL) {
return NULL;
}
for (; i < len; i++) {
dest[i] = src[i];
}
dest[len] = '\0';
return dest;
}
int my_strcmp(const char *s1, const char *s2)
{
int i = 0;
while (s1[i] != '\0' && s2[i] != '\0') {
if (s1[i] != s2[i]) {
return s1[i] - s2[i];
}
i++;
}
return s1[i] - s2[i];
}
char *my_strcpy(char *dest, const char *src)
{
int i = 0;
while (src[i] != '\0') {
dest[i] = src[i];
i++;
}
dest[i] = '\0';
return dest;
}
char *my_strcat(char *dest, const char *src)
{
int i = 0;
int j = 0;
while (dest[i] != '\0') {
i++;
}
while (src[j] != '\0') {
dest[i] = src[j];
i++;
j++;
}
dest[i] = '\0';
return dest;
}