void testprintEnglish() { printf( "Testing printEnglish()\n\n" ); printf( "First line in each group below is the *expected* output.\n" ); printf( "Second line in each group is what *printEnglish* outputs.\n"); printf( "They should match exactly!\n" ); /* * Test with 0. */ printf( "\nTesting with value 0 - should print:\n" "zero\n" ); printEnglish( 0 ); printf( "\n" ); /* * Test with 1. */ printf( "\nTesting with value 1 - should print:\n" "one\n" ); printEnglish( 1 ); printf( "\n" ); /* * Test with 564. */ printf( "\nTesting with value 564 - should print:\n" "five six four\n" ); printEnglish( 564 ); printf( "\n" ); /* * Test with 1333. */ printf( "\nTesting with value 1333 - should print:\n" "one three three three\n" ); printEnglish( 1333 ); printf( "\n" ); printf( "\n\nFinished running tests on printEnglish()\n" ); }
void processIntToken( char* inStr, struct argsInfo info ){ long intToken; int i; ptrError = EINVAL; // Convert string to long intToken = strToLong(inStr, info.inputBase); /* Check for non-integer errors */ if (errno == ptrError) { (void) fprintf(stderr, STR_INT_ENDPTR_ERR, inStr,\ info.inputBase); return; } /* Check for conversion errors */ if (errno) { perror(inStr); return; } /* Print English mode */ if (info.mode & E_FLAG) { /* Check for negative numbers */ if (intToken < 0) { (void) printf(STR_MINUS); // Print out minus sign } printEnglish(abs(intToken)); (void) printf(STR_NEWLINE); } /* Print out the numbers in the given bases*/ for (i = MIN_BASE; i <= MAX_BASE; i++) { // Get the actual base value based on the given flags int realBase = getRealBase(BASE_MASK(i) & info.outputBases); switch (realBase) { case 0: break; /* Print in binary representation*/ case 2: printIntBinary(intToken); break; /* Print out prefix 0 and number in base 8 */ case 8: /* Print out negative sign if negative number */ if (intToken < 0) { (void) printf(STR_NEG_PREFIX); } (void) printf(STR_OCT_PREFIX); printBase(abs(intToken), realBase); (void) printf(STR_NEWLINE); break; /* Print out prefix 0x and number in base 16 */ case 16: /* Print out negative sign if negative number */ if (intToken < 0) { (void) printf(STR_NEG_PREFIX); } (void) printf(STR_HEX_PREFIX); printBase(abs(intToken), realBase); (void) printf(STR_NEWLINE); break; /* Print out number in given bases without prefixes */ default: if (intToken < 0) { (void) printf(STR_NEG_PREFIX); } printBase(abs(intToken), realBase); (void) printf(STR_NEWLINE); break; } } }