~mikec/cs12/hw1/intbase.c-skeleton
(at CSIL), and mind
the comments/instructions in that file.
~mikec/cs12/hw1/intbase
),
including the menu text and all messages.
enum choice menu(void)
, to display a menu for the user, and return
the user's choice as one of the enum choice
constants (see the skeleton).
printf
in this program, but you may use puts
to print a character string (with a newline).
int getInteger(void)
, to get an integer value from the user, and
print the value along with a label that indicates the base that was entered (use exactly
the same labels printed by our solution).
Allow this integer to be entered as a positive or negative decimal,
octal (begins with '0'
), or hexadecimal (begins with "0x"
or "0X"
)
constant. Skip leading white space, then read to the end of the integer. Return 0
if the user
enters invalid text.scanf
, sscanf
, fscanf
,
atoi
, atof
, strtol
, or any other library function to process
the input. Use getchar
to get one character at a time.<ctype.h>
, and you may
model your solution after the simpler atoi
implementation given in the K&R text on page 61.
void putDecimal(int value)
- to display in base 10.
void putOctal(int value)
- to display in base 8.
void putHex(int value)
- to display in base 16.
void putBinary(int value)
- to display in base 2.
printf
(or related library functions) to print the
value.
Use putchar
to print the value one character at a time.itoa
and exercise 3-5 on K&R page 64. Our solution includes the
itob
function described in the exercise (plus reverse
from page
62), and we used this function to easily implement
all four of these required display functions.main
to present the menu and respond to the users choices until the user chooses
to quit. Let the initial value be 0
, in case the user chooses to display a value before
entering one.
gcc -Wall -o intbase intbase.c
" and fix as necessary to
eliminate all compiler errors and warnings before turning in. Test the executable
file too.
turnin hw1@cs12 intbase.c