~cs60/hw1/intbase.c-skeleton
(at CSIL), and mind
the comments/instructions in that file.
enum choice menu(void)
, is
already provided. Use it, and do not change it.
~cs60/hw1/intbase
),
including all messages. Note that you may not copy the executable solution, but you can run it from
its current location - just type its full name to do so, or cd into its directory to run it as usual.
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.
-Wall
option,
and make sure that not even warning messages are issued:
gcc -Wall -o intbase intbase.c
turnin hw1@cs60 intbase.c