learning-cc4e

Solution to https://cc4e.com/. If you copy these you're not right in the head.
git clone https://kaka.farm/~git/learning-cc4e
Log | Files | Refs

solution.c (420B)


      1 void reverse();
      2 
      3 void itob(n, s)
      4 int n;
      5 char s[];
      6 {
      7   char *s_ptr;
      8   s_ptr = s;
      9 
     10   do {
     11     *s_ptr++ = (n % 2) + '0';
     12     n /= 2;
     13   } while (n != 0);
     14 
     15   *s_ptr = '\0';
     16 
     17   reverse(s);
     18 }
     19 void itoh(n, s)
     20 int n;
     21 char s[];
     22 {
     23   char *s_ptr;
     24   s_ptr = s;
     25 
     26   do {
     27     *s_ptr++ = (n % 16)
     28       + (
     29       ((n % 16) < 10)
     30       ? '0'
     31       : ('a' - 10)
     32       );
     33     n /= 16;
     34   } while (n != 0);
     35 
     36   *s_ptr = '\0';
     37 
     38   reverse(s);
     39 }