thanks i am just really tired completely spaced my mind to define them XD, for those who are interested in the correct code here it is:
Code:
/*
*
* Converts an input integer to another base. The
* input and/or the output can be in decimal, octal
* or hexadecimal.
*/
/* Include Files */
#include <stdio.h>
/* Constant Declarations */
#define TRUE 1
#define FALSE 0
/* Function Prototypes */
char get_char_and_clear( void );
char get_quit_char_and_clear( void );
void display( int, char, char );
void distinguish( int, char );
int main( void )
{
int number;
char inbase, outbase, quit = 'A';
printf( "INTEGER CONVERSION PROGRAM\n" );
printf( "--------------------------\n\n" );
/* while loop will input and convert one number */
while ( quit != 'n' && quit != 'N' ) {
printf( "Base of input (d=decimal, h=hexadecimal, o=octal): " );
inbase = get_char_and_clear();
printf( "Number: " );
if (inbase == 'd' )
scanf( "%d", &number );
else if ( inbase == 'h' )
scanf( "%x", &number );
else if ( inbase == 'o' )
scanf( "%o", &number );
printf( "Base of output (d=decimal, h=hexadecimal, o=octal): " );
outbase = get_char_and_clear();
display( number, inbase, outbase );
printf( "Another number? (Y/N) " );
quit = get_quit_char_and_clear();
}
return 0;
}
/* Function: get_char_and_clear()
*
* Gets either a 'd', a 'h', or an 'o', from the user.
* and clears extraneous characters and the newline
* from the input buffer.
*/
char get_char_and_clear( void )
{
int inchar;
while ( ((inchar = getchar()) != 'd') && (inchar != 'h') && (inchar != 'o') )
;
while ( getchar() != '\n' )
;
return (char) inchar;
}
/* Function: get_quit_char_and_clear()
*
* Gets any non-white character from the user.
* and clears extraneous characters and the newline
* from the input buffer.
*/
char get_quit_char_and_clear()
{
int inchar;
while ( (inchar = getchar()) == ' ' || inchar == '\t' && inchar != '\n' )
;
while ( getchar() != '\n' )
;
return (char)inchar;
}
/* Function: display()
* displays the original number and the converted result
*/
void display( int num, char in, char out )
{
printf( "The number" );
distinguish( num, in );
printf( " is" );
distinguish ( num, out );
printf( ".\n" );
}
/* Function: distinguish()
*
* Looks at base and displays num in the correct base
*/
void distinguish( int num, char base )
{
if ( base == 'd' )
printf( " %d in decimal", num );
else if ( base == 'h' )
printf( " %x in hexadecimal", num );
else if ( base == 'o' )
printf( " %o in octal", num );
}