-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.c
162 lines (148 loc) · 2.27 KB
/
lib.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include "lib.h"
int len(char *azerty) //calcule la longeur d'une chaine de caractère
{
int i=0;
while (*azerty++)
i++;
return i;
}
int s_to_num(char *s) //transfère les nombre dans les char/array en int
{
int res=0, sign=1;
if (*s == '-')
{
sign=-1;
s++;
}
else if (*s == '+')
{
s++;
}
for (;*s;s++)
{
if (*s-'0'<0||*s-'0'>9)
{
break;
}
res=res*10+(*s-'0');
}
return sign*res;
}
void sort_tab(int *tab, int size) //range un tableau par ordre croissant
{
int i;
int d;
int stock;
for(i=0;i<size;i++)
{
for(d=i+1;d<size;d++)
{
if (tab[i]>tab[d])
{
stock=tab[i];
tab[i]=tab[d];
tab[d]=stock;
}
}
}
}
void show_tab(int *tab, int size) //affiche un tableau
{
int i;
for (i = 0; i < size; i++)
{
if (i != 0)
printf(", ");
printf("%d", tab[i]);
}
printf("\n");
}
char *make_editable_string(char *s) //prend un string existant dans la mémoire et le rend editable
{
int size;
int i;
char *string;
size=len(s);
string=(char *)malloc((size+1) * sizeof(char));
for (i=0;i<=size;i++)
{
string[i]=*(s+i);
}
return string;
}
void strrev(char *s) //inverse les char d'un mot
{
char stock;
int size;
int i;
size=len(s)-1;
for (i=0;i<=(size/2);i++)
{
stock=s[size-i];
s[size-i]=s[i];
s[i]=stock;
}
}
char *num_to_s(int num) //prend un nombre et le transforme en string
{
int original_num=num;
char *s;
int i;
int count;
int sign=0;
for(count=0;num!=0;count++)
{
num=num/10;
}
num=original_num;
if (num<0)
{
sign=1;
count++;
num=num*-1;
}
//la count = le nombre de "caractère" dans notre nombre
s=prep_str(count);
for(i=0;i<count;i++)
{
s[count-i-1]=num%10+'0';
num=num/10;
}
if (sign)
{
s[0]='-';
}
return s;
}
char *prep_str(int size) //crée un string vide éditable de la tailel désirer
{
char *s;
s = (char*)malloc(size+1);
s[size] = 0;
return s;
}
void putchara(char c) //affiche un caractère
{
write(1, &c, 1);
}
void putnbr(int n) //affiche un nombre/contenu d'une variable numérique
{
putstr(num_to_s(n));
}
void oklm() //retour a la ligne en mode oklm la flemme
{
putstr("\n");
}
void putstr(char *s) //affiche une chaine de caractère
{
for(;*s;s++)
{
putchara(*s);
}
}
void ayy() //le dank meme generator 2k666
{
putstr("ayy");
oklm();
putstr("lmao");
}