Watcom C Library Reference : delay, difftime, _disable, _displaycursor, div

 

 

 

 

delay

 

Synopsis : #include <i86.h> 

              void delay ( unsigned milliseconds );

Description : The delay function suspends execution by the specified number of milliseconds.

 

 

Returns : The delay function has no return value.

 

 

See Also : sleep

Example :

#include <i86.h>


void main( )

{
    sound( 200 );

    delay ( 500 );       /* delay for 1/2 second */

    nosound( );

 

Classification : WATCOM
Systems : All

 

 

 

 

 

difftime

 

Synopsis : #include <time.h> 

              double difftime ( time_t time1, time_t time0 );

Description : The difftime function calculates the difference between the two calendar times:

                 time1 - time0

 

 

Returns : The difftime function returns the difference between the two times in seconds as a double.

 

 

See Also : asctime, clock, ctime, gmtime, localtime, mktime, strftime, time, tzset



Example :

#include <stdio.h> 

#include <time.h>


void compute ( void );

 

void main( )

{
    time_t start_time, end_time;


    start_time = time ( NULL );

    compute( );

    end_time = time ( NULL );

    printf( "Elapsed time: %f seconds\n", difftime( end_time, start_time ) );

}


void compute( void )
{
    int i,  j;
    for( i = 1; i <= 20; i++ ) {

        for( j = 1; j <= 20; j++ )
            printf( "%3d ", i * j );

        printf( "\n" );

    }

}

 

Classification : ANSI
Systems : All

 

 

 

 

 

_disable

 

Synopsis : #include <i86.h> 

              void _disable( void );

Description : The _disable function causes interrupts to become disabled.

The _disable function would be used in conjunction with the _enable function to sure that a sequence of  instructions are executed without any intervening interrupts occurring.

 

 

Returns : The _disable function returns no value.

 

 

See Also : _enable



Example :

#include <stdio.h> 

#include <stdlib.h> 

#include <i86.h>


struct list_entry {
    struct list_entry *next;
    int data;

};

 

volatile struct list_entry *ListHead = NULL;

volatile struct list_entry *ListTail = NULL;


void insert ( struct list_entry *new_entry )

{
    /* insert new_entry at end of linked list */

    new_entry->next = NULL;

    _disable( );    /* disable interrupts */ 

 

    if( ListTail == NULL ) {
        ListHead = new_entry;

    } else {
        ListTail->next = new_entry;

    }
    List Tail = new_entry;

    _enable( );    /* enable interrupts now */

}

 

void main( )

{
    struct list_entry *p;

    int i;

   

    for( i = 1; i <= 10; i++ ) {

        p = ( struct list_entry * ) malloc ( sizeof ( struct list_entry ) );

        if ( p == NULL ) break;

        p->data = i;

        insert ( p );

    }

}

 

Classification : Intel
Systems : All

 

 

 

 

 

_displaycursor

 

Synopsis : #include <graph.h> 

              short _FAR _displaycursor( short mode );

Description : The _displaycursor function is used to establish whether the text cursor is to be displayed when graphics functions complete. On entry to a graphics function, the text cursor is turned off. When the function completes, the mode setting determines whether the cursor is turned back on.

 

The mode argument can have one of the following values:

 Value  Meaning
 _GCURSORON  the cursor will be displayed
 _GCURSOROFF  the cursor will not be displayed

 


Returns : The _displaycursor function returns the previous setting for mode.

 

 

See Also : _gettextcursor, _settextcursor

Example :

#include <stdio.h> 

#include <graph.h>


main( )

{
    char buf[ 80 ];


    _setvideomode ( _TEXTC80 );

    _settextposition ( 2, 1 );

    _displaycursor( _GCURSORON );

    _outtext( "Cursor ON\n\nEnter your name >>" );

    gets ( buf );

 

    _displaycursor( _GCURSOROFF );

    _settextposition ( 6, 1 );

    _outtext ( "Cursor OFF\n\nEnter your name >>" );

    gets ( buf );

 

    _setvideomode ( _DEFAULTMODE );

}

 

Classification : PC Graphics
Systems : DOS, QNX

 

 

 

 

 

div

 

Synopsis : #include <stdlib.h> 

              div_t div( int numer, int denom );

              typedef struct {

                         int quot;      /* quotient */
                         int rem;       /* remainder */

              } div_t;


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

 

 

Returns : The div function returns a structure of type div_t which contains the fields quota and rem.

 

 

See Also : ldiv

Example :

#include <stdio.h>

#include <stdlib.h>


void print_time ( int seconds )

{
    auto div_t min_sec;


    min_sec = div( seconds, 60 );

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

}


void main( )

{
    print_time ( 130 );

}

 


produces the following :
It took 2 minutes and 10 seconds

 

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