/*******************************************************************/ /* (c) Copyright Roger Lacroix 1998 | | | | Designed, developed and programmed by Roger Lacroix | +------------------------------------------------------------------*/ #pragma subtitle ("CharToInt") #pragma page () /*----------------------------------------------------+ | Routine: CharToInt | | | | Purpose: This is a general purpose function to | | convert a number in a character format | | to an integer in a binary format. | | | | Input: | | IntegerPtr - pointer to an integer | | String - pointer to a character string | | Length - length of the character string. | | | | Output: | | None. | | | | Messages: | | None. | | | | Return codes: | | 0 - The function completed successfully. | | 8 - The function failed. | | | | Abend Codes: | | None. | | | | Called Routines: | | None. | | | +----------------------------------------------------*/ static int CharToInt( int * IntegerPtr, char * String, int Length ) { /*------------------------------------------------------+ | Variable declarations. | +------------------------------------------------------*/ auto int CiRC=0; // function return code auto char WorkBuffer[81]; // 80 chars. plus null auto char WorkLength[81]; // 80 chars. plus null /*------------------------------------------------------+ | Constant definitions. | +------------------------------------------------------*/ /*------------------------------------------------------+ | Code section | +------------------------------------------------------*/ if ( (Length > 0 ) AND (Length <= 80) ) { sprintf( WorkLength, // build sprintf string map "%%%d.%ds", Length, Length ); sprintf( WorkBuffer, // move character format num WorkLength, String ); *IntegerPtr = atoi(WorkBuffer); // convert to integer } else { CiRC = 8; // Cannot handle the length } return ( CiRC ); } #pragma subtitle ("IntToChar") #pragma page () /*----------------------------------------------------+ | Routine: IntToChar | | | | Purpose: This is a general purpose function to | | convert an integer in birary format to | | a number in a character format. | | | | Input: | | String - pointer to a character string | | Interger - an inputted interger | | Length - length of the character string. | | | | Output: | | None. | | | | Messages: | | None. | | | | Return codes: | | 0 - The function completed successfully. | | 8 - The function failed. | | | | Abend Codes: | | None. | | | | Called Routines: | | None. | | | +----------------------------------------------------*/ static int IntToChar( char * String, int Integer, int Length ) { /*------------------------------------------------------+ | Variable declarations. | +------------------------------------------------------*/ auto int IcRC=0; // function return code auto char WorkBuffer[81]; // 80 chars. plus null auto char WorkLength[81]; // 80 chars. plus null /*------------------------------------------------------+ | Constant definitions. | +------------------------------------------------------*/ /*------------------------------------------------------+ | Code section | +------------------------------------------------------*/ if ( (Length > 0 ) AND (Length <= 80) ) { sprintf( WorkLength, // build sprintf string map "%%0%dd", Length ); sprintf( WorkBuffer, // convert to char. format WorkLength, Integer ); memcpy( String, // move without terminating null WorkBuffer, Length ); } else { IcRC = 8; // Cannot handle the length } return ( IcRC ); }