Created
January 21, 2018 17:04
-
-
Save iomonad/7d404125d571517336acfe14e7659a12 to your computer and use it in GitHub Desktop.
Itoa Base
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= Host-specific information ==================================================== | |
$> hostname; uname -msr | |
e2r10p19.42.fr | |
Darwin 16.7.0 x86_64 | |
$> date | |
Sun Jan 21 17:56:05 CET 2018 | |
$> gcc --version | |
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 | |
Apple LLVM version 9.0.0 (clang-900.0.38) | |
Target: x86_64-apple-darwin16.7.0 | |
Thread model: posix | |
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin | |
$> clang --version | |
Apple LLVM version 9.0.0 (clang-900.0.38) | |
Target: x86_64-apple-darwin16.7.0 | |
Thread model: posix | |
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin | |
= User files collection ======================================================== | |
Collecting user files from Vogsphere | |
Repository URL: auto-exam/2018/c-exam-alone-in-the-dark-beginner/practice-exam_20180121/ctrouill7 | |
= Git history ================================================================== | |
$> git -C /var/folders/hl/r9fd_n5925l34ryqph0r5hzw0000gq/T/tmpWy1h2G/user log --pretty='%H - %an, %ad : %s' | |
66de9b69d90c9655bc1d22bed358dcc407761f4f - Clement Trosa, Sun Jan 21 17:55:55 2018 +0100 : workaround for ant being a pile of fail | |
= Collected files ========================================== | |
$> ls -lAR /var/folders/hl/r9fd_n5925l34ryqph0r5hzw0000gq/T/tmpWy1h2G/user | |
total 8 | |
-rw-r--r-- 1 deepthought deepthought 283 Jan 21 17:56 __GIT_HISTORY | |
drwxr-xr-x 3 deepthought deepthought 102 Jan 21 17:56 ft_itoa_base | |
/var/folders/hl/r9fd_n5925l34ryqph0r5hzw0000gq/T/tmpWy1h2G/user/ft_itoa_base: | |
total 8 | |
-rw-r--r-- 1 deepthought deepthought 1511 Jan 21 17:56 ft_itoa_base.c | |
= ft_itoa_base ================================================================= | |
$> clang -Wextra -Wall -Werror ft_itoa_base.c main.c -o user_exe | |
= Test 1 =================================================== | |
$> ./ni6km1o2evqmfpssfjqnhx87 | |
$> diff -U 3 user_output_test1 test1.output | cat -e | |
Diff OK :D | |
= Test 2 =================================================== | |
$> ./fcawlpeqsbl881m1vmm881dr "21" "2313" "12" | |
$> diff -U 3 user_output_test2 test2.output | cat -e | |
Diff OK :D | |
= Test 3 =================================================== | |
$> ./upwmr6xrfesisgrd4lsc4va7 "2147483647" "10" | |
$> diff -U 3 user_output_test3 test3.output | cat -e | |
Diff OK :D | |
= Test 4 =================================================== | |
$> ./imi37cphkqvqhdulawaja49h "-2147483648" "10" | |
$> diff -U 3 user_output_test4 test4.output | cat -e | |
Diff OK :D | |
= Test 5 =================================================== | |
$> ./jrm2e8lo2wsxpl0qhybdehb4 "0" "2" | |
$> diff -U 3 user_output_test5 test5.output | cat -e | |
Diff OK :D | |
= Test 6 =================================================== | |
$> ./194zxvg31b0jxt9u8s3e60sf "--223" "10" | |
$> diff -U 3 user_output_test6 test6.output | cat -e | |
Diff OK :D | |
= Test 7 =================================================== | |
$> ./rxk58xn99kwb7nwmh5j7vs1w "1111129498" "2" | |
$> diff -U 3 user_output_test7 test7.output | cat -e | |
Diff OK :D | |
= Test 8 =================================================== | |
$> ./y83i3wnlaawbiumbdzrhsd6w "490015378" "2" | |
$> diff -U 3 user_output_test8 test8.output | cat -e | |
Diff OK :D | |
= Test 9 =================================================== | |
$> ./871t8ysqhgb9l9hcf43edy7r "1349764449" "10" | |
$> diff -U 3 user_output_test9 test9.output | cat -e | |
Diff OK :D | |
= Test 10 ================================================== | |
$> ./gdhx5tshmh6kimcrmjmxggmo "1312216772" "12" | |
$> diff -U 3 user_output_test10 test10.output | cat -e | |
Diff OK :D | |
= Test 11 ================================================== | |
$> ./38h9pturznowediioefybkt7 "621676416" "16" | |
$> diff -U 3 user_output_test11 test11.output | cat -e | |
Diff OK :D | |
= Test 12 ================================================== | |
$> ./66u8ap5yx2kxyclvhed4j039 "986713785" "15" | |
$> diff -U 3 user_output_test12 test12.output | cat -e | |
Diff OK :D | |
= Test 13 ================================================== | |
$> ./0o7y9sxfi4i0l4vfn803h305 "79475820" "10" | |
$> diff -U 3 user_output_test13 test13.output | cat -e | |
Diff OK :D | |
= Test 14 ================================================== | |
$> ./zy431ckr2cbwdshlgqhog6of "1985516224" "15" | |
$> diff -U 3 user_output_test14 test14.output | cat -e | |
Diff OK :D | |
= Test 15 ================================================== | |
$> ./q0n4xabu18wxwu8zqvh9rsuo "1812285997" "5" | |
$> diff -U 3 user_output_test15 test15.output | cat -e | |
Diff OK :D | |
= Test 16 ================================================== | |
$> ./ctl583p8xq8hyp6jyfj15ga3 "441862614" "6" | |
$> diff -U 3 user_output_test16 test16.output | cat -e | |
Diff OK :D | |
= Test 17 ================================================== | |
$> ./0lh987gfpwu4g2s6tt0icpb6 "319515338" "14" | |
$> diff -U 3 user_output_test17 test17.output | cat -e | |
Diff OK :D | |
= Test 18 ================================================== | |
$> ./1jg4yivofi5ww6jkhql9fxdb "184706715" "7" | |
$> diff -U 3 user_output_test18 test18.output | cat -e | |
Diff OK :D | |
= Test 19 ================================================== | |
$> ./cpd29x020i73bgozihdebcin "1783723596" "9" | |
$> diff -U 3 user_output_test19 test19.output | cat -e | |
Diff OK :D | |
= Test 20 ================================================== | |
$> ./73lzng9kynmhs8nv2ndurb41 "202569" "7" | |
$> diff -U 3 user_output_test20 test20.output | cat -e | |
Diff OK :D | |
Grade: 1 | |
= Final grade: 1 =============================================================== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static inline char | |
get_ascii(int c) { | |
c = (c < 0) ? -c : c; | |
return ((c <= 9) ? c + '0' | |
: c - 10 + 'A'); | |
} | |
char | |
*ft_itoa_base(int value, int base) { | |
int i, sign; | |
char *ret; | |
/* Handle int overflow */ | |
long cast = (long)value; | |
/* Alloc ret*/ | |
if (!(ret=(char*)malloc(sizeof(char) * 34))) { | |
return (NULL); | |
} | |
/* Determine sign */ | |
sign = (cast < 0) ? -1 : 1; | |
/* Handle nil bases and casts */ | |
if (cast == 0 || base < 2) { | |
ret[0] = '0'; | |
ret[1] = '\0'; | |
return (ret); | |
} | |
/* Update cursors */ | |
ret[33] = '\0'; | |
i = 32; | |
/* Compute allocation */ | |
while (cast) { | |
ret[i] = get_ascii(cast % base); | |
cast = cast / base; | |
i--; | |
} | |
/* Handle final sign */ | |
if (base == 10 && sign == -1) { | |
ret[i] = '-'; | |
} else { | |
i++; | |
} | |
/* Update cursors to array start */ | |
ret += i; | |
return (ret); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment