1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
// IMPLEMENTATION code
#include <stdio.h>
#include "print_integer.h"

void print_integer(int n, int radix, char* prefix) {
    // Do not say this function will "convert" n from some base to base 'radix'.
    // This function "expresses" n in base 'radix'.

    fputc('0' + n, stdout); // GOOD  ... Okay to copy/adapt this line.

    //fputc(48 + n, stdout);  // BAD!!! ... Understanding code should not require
    //                        //            checking/remembering the ASCII table.

    // fputc(49 + n, stdout);  // BUG!!! ... can be solved by simply fixing code quality.
}

© Copyright 2022 Alexander J. Quinn         This content is protected and may not be shared, uploaded, or distributed.