Perform division on long integers
#include <stdlib.h> ldiv_t ldiv( long int numer, long int denom );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The ldiv() function calculates the quotient and remainder of:
numer / denom
A structure of type ldiv_t that contains the following members:
typedef struct { long int quot; /* quotient */ long int rem; /* remainder */ } ldiv_t;
#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.
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |