/* chrprb.c 09 October 2000 */ void main ( void ); void test01 ( void ); void test02 ( void ); void test03 ( void ); void test04 ( void ); void test05 ( void ); void test06 ( void ); void test07 ( void ); void test08 ( void ); #include #include #include #include "chrpakc.h" /******************************************************************************/ void main ( void ) { /******************************************************************************/ printf ( "\n" ); printf ( "CHRPRB\n"); printf ( " Test CHRPAK routines for character manipulation.\n"); print_sizes ( ); test01 ( ); test02 ( ); test03 ( ); test04 ( ); test05 ( ); test06 ( ); test07 ( ); test08 ( ); exit ( EXIT_SUCCESS ); } /******************************************************************************/ void test01 ( void ) { /******************************************************************************/ char c; char c2; printf ( "\n" ); printf ( "TEST01\n" ); printf ( " CHAR_CAP capitalizes a character;\n" ); printf ( " CHAR_LOW lowercases it.\n" ); c = 'f'; printf ( "%c\n", c ); c2 = char_cap ( c ); printf ( "%c\n", c2 ); c2 = char_low ( c ); printf ( "%c\n", c2 ); return; } /******************************************************************************/ void test02 ( void ) { /******************************************************************************/ char string[25]; printf ( "\n" ); printf ( "TEST02\n" ); printf ( " STRING_CAP capitalizes a string;\n" ); printf ( " STRING_LOW lowercases it.\n" ); strcpy ( string, "HELLO World, how ARE you?" ); printf ( "%s\n", string ); string_cap ( string ); printf ( "%s\n", string ); strcpy ( string, "HELLO World, how ARE you?" ); string_low ( string ); printf ( "%s\n", string ); return; } /******************************************************************************/ void test03 ( void ) { /******************************************************************************/ char c; int j; char string[25]; printf ( "\n" ); printf ( "TEST03\n"); printf ( " CHAR_INDEX_LAST finds the last occurrence of a character.\n" ); strcpy ( string, "HELLO World, how ARE you?" ); printf ( "%s\n", string ); c = 'o'; j = char_index_last ( string, c ); printf ( "Last occurrence of %c is at %d.\n", c, j ); return; } /******************************************************************************/ void test04 ( void ) { /******************************************************************************/ char string1[10]; char string2[8]; printf ( "\n" ); printf ( "TEST04\n"); printf ( " S_EQI reports if two strings are equal, ignoring case.\n" ); printf ( "\n" ); strcpy ( string1, "HELLO" ); printf ( "STRING1: %s\n", string1 ); strcpy ( string2, "HeLLO" ); printf ( "STRING2: %s\n", string2 ); printf ( "S_EQI(STRING1,STRING2) = %d\n", s_eqi ( string1, string2 ) ); printf ( "\n" ); strcpy ( string1, "HELP ME" ); printf ( "STRING1: %s\n", string1 ); strcpy ( string2, "HELP" ); printf ( "STRING2: %s\n", string2 ); printf ( "S_EQI(STRING1,STRING2) = %d\n", s_eqi ( string1, string2 ) ); return; } /******************************************************************************/ void test05 ( void ) { /******************************************************************************/ int i; char *s; printf ( "\n" ); printf ( "TEST05\n"); printf ( " CHRMON returns the name of the I-th month.\n" ); printf ( "\n" ); printf ( " I Month\n" ); printf ( "\n" ); for ( i = 0; i <= 12; i++ ) { s = chrmon ( i ) ; printf ( "%d %s\n", i, s ); } return; } /******************************************************************************/ void test06 ( void ) { /******************************************************************************/ int char_index; int null_index; int result; char string[25]; printf ( "\n" ); printf ( "TEST06\n"); printf ( " CHAR_PAD places spaces around a character.\n" ); printf ( "\n" ); strcpy ( string, "I vant to be alone!" ); printf ( "The string is : %s\n", string ); printf ( "We will try to place spaces around the A in ALONG.\n" ); char_index = 13; null_index = strlen ( string ); result = char_pad ( &char_index, &null_index, string, 25 ); if ( result == ERROR ) { printf ( "The operation failed.\n" ); } else { printf ( "The string is : %s\n", string ); } return; } /******************************************************************************/ void test07 ( void ) { /******************************************************************************/ int ival; unsigned int ival2; unsigned char string[4]; printf ( "\n" ); printf ( "TEST07\n"); printf ( " INT2BYTE converts an INT to a string,\n" ); printf ( " BYTE2INT converts it back.\n" ); printf ( "\n" ); printf ( " IVAL Recovered IVAL\n" ); printf ( "\n" ); ival = 3; int2byte ( ival, string ); byte2int ( string, &ival2 ); printf ( "%d %d\n", ival, ival2 ); ival = 1952; int2byte ( ival, string ); byte2int ( string, &ival2 ); printf ( "%d %d\n", ival, ival2 ); ival = 123456789; int2byte ( ival, string ); byte2int ( string, &ival2 ); printf ( "%d %d\n", ival, ival2 ); return; } void test08 ( void ) { /******************************************************************************/ /* TEST08 tests C_COUNT_FILE_ADD. */ int count[256]; printf ( "\n" ); printf ( "TEST08\n" ); printf ( " C_COUNT_FILE_ADD adds the characters in a file\n" ); printf ( " to a character count.\n" ); printf ( " DEBUG, call C_COUNT_INT:\n" ); c_count_init ( count ); printf ( " DEBUG, call C_COUNT_FILE_ADD:\n" ); c_count_file_add ( "chrprb.c", count ); printf ( " DEBUG, call C_COUNT_PRINT:\n" ) ; c_count_print ( count, "Raw character count data:" ); /* c_count_histogram_print ( count, "Data from CHRPRB.C:" ); */ return; }