WATCOM C Library Reference : _bios_timeofday, _bprint, bsearch

 

 

 

 

_bios_timeofday

 

Synopsis : #include <bios.h> 

              int _bios_timeofday ( int service, long *timeval );

Description : The _bios_timeofday function uses INT 0x1A to get or set the current system clock value. The values for service are:

 

 Value  Meaning
 _TIME_GETCLOCK  Places the current system clock value in the location pointed to by timeval. The function  returns zero if midnight has not passed since the last time the system clock was read or set; otherwise, it returns 1.
 _TIME_SETCLOCK  Sets the system clock to the value in the location pointed to by timeval.

 


Returns :  A value of -1 is returned if neither _TIME_GETCLOCK nor _TIME_SETCLOCK were specified; otherwise 0 is returned.

 


Example :

#include <stdio.h> 

#include <bios.h>


void main( )

{
    long time_of_day;
    _bios_timeofday ( _TIME_GETCLOCK, &time_of_day );

    printf( "Ticks since midnight : %lu\n", time_of_day );

}

 

produces the following :

Ticks since midnight : 762717

 

Classification : BIOS
Systems : DOS, Win, NT, DOS/PM

 

 

 

 

_bprint

 

Synopsis : #include <stdio.h> 

              int _bprintf( char *buf, unsigned int bufsize, const char *format, ... );


Description : The _bprintf function is equivalent to the sprintf function, except that the argument bufsize specifies the size of the character array buf into which the generated output is placed.

 

A null character is placed at the end of the generated character string. The format string is described under the description of the printf function.

 

 

Returns : The _bprintf function returns the number of characters written into the array, not counting the terminating null character. An error can occur while converting a value for output. When an error has occurred, errno contains a value indicating the type of error that has been detected.

 

 

See Also : cprintf, fprintf, printf, sprintf, _vbprintf, vcprintf, vfprintf, vprintf, vsprintf

 


Example :

#include <stdio.h>

void main( int argc, char *argv[ ] ) 

{
    char file_name[9];

    char file_ext [4];


    _bprintf( file_name, 9, "%s", argv[1] );

    _bprintf( file_ext, 4, "%s", argv[2] );

    printf( "%s.%s\n", file_name, file_ext );

}

 

Classification : WATCOM
Systems : All

 

 

 

 

bsearch

 

Synopsis : #include <stdlib.h> 

              void *bsearch ( const void *key,

                                const void *base,

                                size_t num, 

                                size_t width,

                                int (*compar) ( const void *pkey, const void *pbase) );


Description : The bsearch function performs a binary search of a sorted array of num elements, which is
pointed to by base, for an item which matches the object pointed to by key. Each element in the array is width bytes in size.

 

The comparison function pointed to by compar is called with two arguments that point to elements in the array. The first argument pkey points to the sat object pointed to by key. The second argument pbase points to a element in the array. The comparison function shall return an integer less than, equal to, or greater than zero if the key object is less than, equal to, or greater than the element in the array.

 

 

Returns : The bsearch function returns a pointer to the matching member of the array, or NULL if a matching object could not be found. If there are multiple values in the array which are equal to the key, the return value is not necessarily the first occurrence of a matching value when the array is searched linearly.

 

 

See Also : lfind, lsearch, qsort

 


Example :

#include <stdio.h> 

#include <stdlib.h> 

#include <string.h>


static const char *keywords[ ] = {
        "auto",

        "break",

        "case",
        "char", 

        /*  .  */

        /*  .  */

        /*  .  */
        "while"

};


#define NUM_KW         sizeof (keywords) / sizeof (char *)

 

int kw_compare ( const void *p1, const void *p2 )

{
    const char *p1c = (const char *) p1;

    const char **p2c = (const char **) p2;

    return( strcmp( plc, *p2c ) );

}


int keyword_lookup ( const char *name )

{
    const char **key;

    key = (char const **) bsearch ( name, keywords, NUM_KW, sizeof( char * ), kw_compare );

    if( key == NULL ) return( -1 );

    return key - keywords;

}


void main( )

{
    printf( "%d\n", keyword_lookup ( "case" ) );

    printf( "%d\n", keyword_lookup ( "crigger" ) );

    printf( "%d\n", keyword_lookup ( "auto" ) );

}

//***************** Sample program output ************
// 2

// -1

// 0

 

produces the following :

2

-1

0

 

Classification : ANSI
Systems : All

 

 

 

 

 

 

 

This manual describes the WATCOM C library for DOS, Windows, and OS/2, It includes the Standard C Library (as defined in the ANSI C Standard).

 

WATCOM C Language Reference manual describes the ANSI C Programming language and extensions to it which are supported by WATCOM C/C++ (32bit)

 

 

 

728x90
반응형
Posted by 전화카드
,