Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/l/ldiv.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/l/ldiv.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/l/ldiv.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/l/ldiv.html on line 8

ldiv()

Perform division on long integers

Synopsis:

#include <stdlib.h>

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

Arguments:

numer
The numerator.
denom
The denominator.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The ldiv() function calculates the quotient and remainder of:

numer / denom

Returns:

A structure of type ldiv_t that contains the following members:

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

Examples:

#include <stdio.h>
#include <stdlib.h>

void print_time( long ticks )
{
    ldiv_t sec_ticks;
    ldiv_t min_sec;

    sec_ticks = ldiv( ticks, 100 );
    min_sec = ldiv( sec_ticks.quot, 60 );

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

int main( void )
{
    print_time( 86712 );
    
    return EXIT_SUCCESS;
}

produces the output:

It took 14 minutes and 27 seconds.

Classification:

ANSI, POSIX 1003.1

Safety:
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

div()


Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/l/ldiv.html on line 164

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/l/ldiv.html on line 164