-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmy_stdio.5.c
More file actions
49 lines (46 loc) · 1.23 KB
/
my_stdio.5.c
File metadata and controls
49 lines (46 loc) · 1.23 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
/*******************************************************************************
*
* File Name : my_stdio.5.c
* Created By : Thomas Aurel
* Creation Date : April 22th, 2015
* Last Change : April 22th, 2015 at 23:10:55
* Last Changed By : Thomas Aurel
* Purpose :
*
*******************************************************************************/
#include <stddef.h>
#include "my_stdio.h"
#include "my_string.h"
charlist * convert_itocl(int i, int b){
charlist *nbr = NULL;
if (i < 0){
addItem('-', nbr);
i = (-1) * i;
}
if (i > b){
nbr = concatItem(nbr, convert_itocl(i, b));
} else {
nbr = addItem(((i%b) < 10 ? '0' + (i % b) : 'a' + (i%b) - 10), nbr);
}
return nbr;
}
charlist * convert_dtocl(double d, int b){
charlist *nbr = NULL;
int i = d;
d = (d - i) * b;
nbr = concatItem(nbr, convert_itocl(i, b));
nbr = addItem('.', nbr);
do{
i = d;
d = (d - i) * b;
nbr = concatItem(nbr, convert_itocl(i, b));
}while(d != 0.0);
return nbr;
}
charlist * convert_stocl(char *s){
charlist *str = NULL;
for(int i = 0; i < my_strlen(s); i++){
str = addItem(s[i], str);
}
return str;
}