-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
51 lines (41 loc) · 929 Bytes
/
main.c
File metadata and controls
51 lines (41 loc) · 929 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
void *xmalloc(unsigned int size){
void *new_mem = (void *)malloc(size);
if (new_mem == NULL) {
fprintf(stderr, "fatal: memory exhausted (xmalloc of %u bytes).\n", size);
exit(-1);
}
return new_mem;
}
void getTypeSize() {
int i;
char c;
float f;
double d;
printf("int: %ld\n", sizeof(i));
printf("char: %ld\n", sizeof(c));
printf("float: %ld\n", sizeof(f));
printf("double: %ld\n", sizeof(d));
}
int floatlen(float i) { /*without .00*/
return floor(log10(abs(i))) + 1;
}
int intlen(int i) {
return floor(log10(abs(i))) + 1;
}
char *itoa(int i) { /*need strcpy*/
char *str = malloc(intlen(i) * sizeof(char));
snprintf(str, sizeof(str), "%d", i);
return str;
}
// atof atoi atol ltoa already exist
double itof(int i) {
return (float)i;
}
double itod(int i) {
return (double)i;
}