Question: Programming language to use is C In convert.c, there is a function called itob which takes three arguments, a character array (for a buffer) and

Programming language to use is C

In convert.c, there is a function called itob which takes three arguments, a character array (for a buffer) and two numeric arguments.

The first argument is a buffer which has been passed to the function so that it can return a string value, like with fscanf and fgets.

The second argument is the numeric base for which you should be producing the representation.

The third argument, is the actual number that you're producing the representation of.

This function is void, since it is returning the string value through the first argument.

If the number is negative, the function should return the string "0\0".

Follow the process we described in the discussion on Modulo to extract digits from a number.

This function should be able to make use of the digit_itob function on each digit, again to avoid the headache of doing ASCII manipulation in this function.

itob(buffer, 36, 1664957) buffer = "ZOOT"

itob(buffer, 36, 29234652) buffer = "HELLO"

itob(buffer, 10, 2018) buffer = "2018"

itob(buffer, 16, 127) buffer = "7F"

itob(buffer, 10, -1) buffer = "0"

--------------------------------------------------------------------------

This is how I implemented digit_itob

#include

char digit_itob(int number, int base) { if(number < 0 || number >= base || base <= 0 || base > 36) { return '\0'; } else { return "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[number]; } }

int main() { printf("'%c' ", digit_itob( 15, 16)); printf("'%c' ", digit_itob( 0, 10)); printf("'%c' ", digit_itob( 1, 16)); printf("'%c' ", digit_itob( 35, 36)); printf("'%c' ", digit_itob( 35, 10)); printf("'%c' ", digit_itob( 10, 0)); printf("'%c' ", digit_itob( -1, 10)); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!