Conversion Routines


Functions

void cyid2str (char *sz_cy_id, cyid_t cy_id)
cyid_t str2cyid (char *sz_cy_id)
long atoul (char *sz_source)
long xtoi (char *sz_source)
long htoul (char *sz_source)


Detailed Description

These functions are used to convert values from one format to another. Please make special note of cyid2str() and str2cyid(), because they can help to convert CyID to string and vice versa.


Function Documentation

long atoul ( char * sz_source )
 

Converts ASCII decimal into long.

Parameters:
sz_source   a string to be converted.
Returns:
long value produced by interpreting the input characters as a number.
       #include <cywin.h>
       ...
       long amount;
       struct cDialog dialog;
       struct module_t main_module;
       char sz_amount[11];
       ...
       init_module( &main_module );
       ...
       cDialog_ctor( &dialog,
                     "Apples",
                     "Enter amount:",
                     mbOk | mbCancel | mbEdit,
                     10,
                     main_module.m_process );
       if( cDialog_ShowModal( &dialog ) == mrOk )
       {
         cDialog_GetEditText( &dialog, sz_amount );
       }
       cDialog_dtor( &dialog, LEAVE_MEMORY );
       amount = atoul( sz_amount );
       ...

void cyid2str ( char * sz_cy_id,
cyid_t cy_id )
 

Converts CyID from cyid_t to text.

Parameters:
sz_cy_id   buffer for the CyID in text form.
cy_id   CyID to convert.
Returns:
None
       #include <cybiko.h>
       ...
       char sz_str_ID[10];
       cyid_t current_device_id = 0;
       ...
       TRACE( "Devices around:" );
       while( current_device_id = get_people_around( current_device_id ) )
       {
         cyid2str( sz_str_ID, current_device_id );
         TRACE( "%s", sz_str_ID );
       }
       ...
See also:
str2cyid.

long htoul ( char * sz_source )
 

Converts hexadecimal ASCII into long.

Parameters:
sz_source   a string to be converted.
Returns:
long value produced by interpreting the input characters as a hexadecimal value.
       #include <cywin.h>
       ...
       long device_id;
       struct cDialog dialog;
       struct module_t main_module;
       char sz_device_id[11];
       ...
       init_module( &main_module );
       ...
       cDialog_ctor( &dialog,
                     "Connection property",
                     "Enter device id (in hexadecimal form):",
                     mbOk | mbCancel | mbEdit,
                     10,
                     main_module.m_process );
       if( cDialog_ShowModal( &dialog ) == mrOk )
       {
         cDialog_GetEditText( &dialog, sz_device_id );
       }
       cDialog_dtor( &dialog, LEAVE_MEMORY );
       device_id = htoul( sz_device_id );
       ...

cyid_t str2cyid ( char * sz_cy_id )
 

Converts CyID from text form to cyid_t.

Parameters:
sz_cy_id   CyID in text form.
Returns:
CyID in cyid_t form.
       #include <cybiko.h>
       #define MSG_CLIENT_PING    MSG_USER + 1
       ...
       struct Message* ptr_message;
       char sz_game_server_ID[10];
       ...
       //  Obtains sz_game_server_ID.
       ...
       ptr_message = Message_new( sizeof( struct Message ) );
       ptr_message->msgid = MSG_CLIENT_PING;
       Message_post(ptr_message, "game_server", str2cyid( sz_partner_ID ) );
       ...
See also:
cyid2str.

long xtoi ( char * sz_source )
 

Converts some ASCII number into long.
First, this function skips white spaces (including the spaces at the ends of lines), then tries to detect the base by checking the beginning of the number. It understands these hexadecimal prefixes: 'x<hex-val> 0x<hex-val> H'<hex-val> h'<hex-val> -<dec-val> <dec-val>' where hex-val is some set of hexadecimal digits (0123456789ABCDEFabcdef), val - decimal value.

Parameters:
sz_source   a string to be converted.
Returns:
long value produced by interpreting the input characters as a number.
       #include <cywin.h>
       ...
       long device_id;
       struct cDialog dialog;
       struct module_t main_module;
       char sz_device_id[11];
       ...
       init_module( &main_module );
       ...
       cDialog_ctor( &dialog,
                     "Connection property",
                     "Enter device id:",
                     mbOk | mbCancel | mbEdit,
                     10,
                     main_module.m_process );
       if( cDialog_ShowModal( &dialog ) == mrOk )
       {
         cDialog_GetEditText( &dialog, sz_device_id );
       }
       cDialog_dtor( &dialog, LEAVE_MEMORY );
       device_id = xtoi( sz_device_id );
       ...