-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutiles4.c
More file actions
110 lines (95 loc) · 1.42 KB
/
utiles4.c
File metadata and controls
110 lines (95 loc) · 1.42 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "simple_shell.h"
/**
* _strcat - concatenates two strings
* @dest: destination string
* @src: source string
* Return: pointer to the concatenated string
*/
char *_strcat(char *dest, char *src)
{
int i, j;
i = 0;
j = 0;
while (dest[i] != '\0')
i++;
while (src[j] != '\0')
{
dest[i] = src[j];
j++;
i++;
}
dest[i] = '\0';
return (dest);
}
/**
* free_tokens - frees a double pointer
* @ptr: double pointer to be freed
* Return: void
*/
void free_tokens(char **ptr)
{
int i = 0;
while (ptr[i])
{
if (ptr[i])
free(ptr[i]);
i++;
}
if (ptr)
free(ptr);
}
/**
* cut_string - cuts a string when # is encountered
* @str: string to be cut
*/
void cut_string(char *str)
{
int i = 0;
while (str[i])
{
if (str[i] == '#')
{
str[i] = '\0';
return;
}
i++;
}
}
/**
* ft_nbrlen - counts the number of digits in q number
* @n: the number
* Return: the number of digits
*/
int ft_nbrlen(int n)
{
int counter;
counter = 0;
if (n <= 0)
counter++;
while (n)
{
counter++;
n /= 10;
}
return (counter);
}
/**
* _strncmp - compares two strings
* @str1: first string
* @str2: second string
* @n: number of bytes to compare
* Return: 0 if strings are equal, -1 if not
*/
int _strncmp(char *str1, char *str2, int n)
{
int i = 0;
while (str1[i] != '\0' && str2[i] != '\0' && i < n)
{
if (str1[i] != str2[i])
return (-1);
i++;
}
if (i == n)
return (0);
return (-1);
}