//------------------------------------------------------------------- // exitcode.cpp // // This program lets a user specify the value of its exit-code. // (It will be used for demonstrating our 'run.s' application.) // // compile using: $ g++ exitcode.cpp -o exitcode // execute using: $ ./exitcode // // programmer: ALLAN CRUSE // written on: 27 FEB 2008 //------------------------------------------------------------------- #include // for strlen() #include // for write(), read() #include // for strtol() int main( int argc, char **argv ) { // ask the user for input char prompt[] = "Enter hex value for exit-code: "; int len = strlen( prompt ); write( STDOUT_FILENO, prompt, len ); // accept the user's response char buffer[ 8 ] = {0}; read( STDIN_FILENO, buffer, sizeof( buffer ) ); // convert the input-string to an integer long exitcode = strtol( buffer, NULL, 16 ); // now use this integer as a return-value return exitcode; }