-
Notifications
You must be signed in to change notification settings - Fork 0
/
strleni.c
39 lines (34 loc) · 816 Bytes
/
strleni.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
#include <stdio.h>
#include <stdlib.h>
#include "strleni.h"
#include "limits.h"
int main(int argc, char** argv)
{
int base = 10;
if(argc > 1)
{
if(argc > 2)
base = clamp(strtouq(argv[2], NULL, 10), 0, UINT_MAX);
int x = clamp(strtoq(argv[1], NULL, 10), INT_MIN, INT_MAX);
uint8_t len = strlenid(x, base);
switch(base)
{
case 8:
printf("%o:%u\n", x, len);
break;
case 16:
printf("%x:%u\n", x, len);
break;
case 10:
printf("%d:%u\n", x, len);
break;
default:
printf("Usage: %s <decimal integer> [target base] - INTEGER_RANGE: %d-%d\n", argv[0], INT_MIN, INT_MAX);
exit(EXIT_FAILURE);
break;
}
exit(EXIT_SUCCESS);
}
printf("Usage: %s <deciaml integer> [target base] - INTEGER_RANGE: %d-%d\n", argv[0], INT_MIN, INT_MAX);
exit(EXIT_FAILURE);
}