'Watcom C Reference/K - L- M - N'에 해당되는 글 9건

  1. 2021.07.06 Watcom C Library : kbhit, labs, ldexp, ldiv, lfind

 

 

Watcom C Library Reference : kbhit, labs, ldexp, ldiv, lfind

 

 

 

 

kbhit

 

Synopsis : #include <conio.h> 

              int kbhit( void );

 


Description : The kbhit function tests whether or not a keystroke is currently available. When one is available, the function getch or getche may be used to obtain the keystroke in question.


With a stand-alone program, the kbhit function may be called continuously until a keystroke is available.

 

 

Returns : The kbhit function returns zero when no keystroke is available; otherwise, a non-zero value is returned.

 

 

See Also : getch, getche, putch, ungetch

 


Example :

/* * This program loops until a key is pressed * or a count is exceeded. */

#include <stdio.h>

#include <conio.h>


void main( )

{
    unsigned long i;


    printf( "Program looping. Press any key.\n" );

    for( i = 0; i < 10000; i++ ) {

        if( kbhit( ) ) {
            getch( );

            break;

        }

    }

}

 

Classification : WATCOM
Systems : All

 

 

 

 

 

labs

 

Synopsis : #include <stdlib.h> 

              long int labs( long int j );

 


Description : The labs function returns the absolute value of its long-integer argument j.

 

 

Returns : The labs function returns the absolute value of its argument.

 

 

See Also : abs, fabs

 


Example :

#include <stdio.h> 

#include <stdlib.h>


void main( )

{
    long     x, y;


    x = -50000L;

    y = labs( x );

    printf( "labs (%ld) = %ld\n", x, y );

}

 


produces the following :
labs (-50000) = 50000

 

Classification : ANSI
Systems : All

 

 

 

 

 

ldexp

 

Synopsis : #include <math.h> 

              double ldexp( double x, int exp );

 


Description : The ldexp function multiplies a floating-point number by an integral power of 2. A range error may occur.

 

 

Returns : The ldexp function returns the value of x times 2 raised to the power exp.

 

 

See Also : frexp, modf

 


Example :

#include <stdio.h> 

#include <math.h>


void main( )

{
    double     value;
   

    value = ldexp( 4.7072345, 5 );

    printf( "%f\n", value );
}

 


produces the following :
150.631504

 

Classification : ANSI
Systems : All

 

 

 

 

 

ldiv

 

Synopsis : #include <stdlib.h> 

              ldiv_t ldiv( long int numer, long int denom );

 

              typedef struct {
                  long int quot;      /* quotient */
                  long int rem;       /* remainder */

              } ldiv_t;

 


Description : The ldiv function calculates the quotient and remainder of the division of the numerator numer by the denominator denom.

 

 

Returns : The ldiv function returns a structure of type ldiv_t that contains the fields quot and rem, which are both of type long int.

 

 

See Also : div

 


Example :

#include <stdio.h> 

#include <stdlib.h>


void print_time( long int ticks )

{
    ldiv_t     sec_ticks;

    ldiv_t     min_sec;


    sec_ticks = ldiv( ticks, 100L );

    min_sec = ldiv( sec_ticks.quot, 60L );

    printf( "It took %ld minutes and %ld seconds \n", min_sec.quot, min_sec.rem );

}

 


void main( )

{
    print_time( 86712L );

}

 


produces the following :
It took 14 minutes and 27 seconds

 

Classification : ANSI
Systems : All

 

 

 

 

 

lfind

 

Synopsis : #include <search.h> 

              void *lfind( const void *key,       /* object to search for */
                           const void *base,     /* base of search data */

                           unsigned *num,       /* number of elements */

                           unsigned width,       /* width of each element */

                           int (*compare) ( const void *element1, const void *element2 ) );


Description : The lfind function performs a linear search for the value key in the array of num elements pointed to by base. Each element of the array is width bytes in size.

 

The argument compare is a pointer to a user-supplied routine that will be called by lfind to determine the relationship of an array element with the key. One of the arguments to the compare function will be an array element, and the other will be key.

 

The compare function should return 0 if element1 is identical to element2 and non-zero if the elements are not identical.

 

 

Returns : The lfind function returns a pointer to the array element in base that matches key if it is found, otherwise NULL is returned indicating that the key was not found.

 

 

See Also : bsearch, lsearch

 


Example :

#include <stdio.h> 

#include <stdlib.h> 

#include <string.h> 

#include <search.h>


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

    "break",

    "case",

    "char",

    /*  .  */ 

    /*  .  */ 

    /*  .  */ 

    "while"

};

 

 

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

{
    unsigned num = 5;

    int compare( const void *, const void * );

 

    if( argc <= 1 ) exit ( EXIT_FAILURE );

    if( lfind( &argv[1], keywords, &num, sizeof(char **), compare ) == NULL) { 

        printf( "'%s' is not a C keyword\n", argv[1] );
        exit( EXIT_FAILURE );

    } else {
        printf( "'%s' is a C keyword\n", argv[1] );

        exit( EXIT_SUCCESS );

    }

}

 


int compare( const void *op1, const void *op2 )

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

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

    return( strcmp ( *p1, *p2 ) ) ;

}

 

Classification : WATCOM
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 전화카드
,