Node:I/O of Rationals, Previous:Applying Integer Functions, Up:Rational Number Functions
When using any of these functions, it's a good idea to include stdio.h
before gmp.h
, since that will allow gmp.h
to define prototypes
for these functions.
Passing a NULL
pointer for a stream argument to any of these
functions will make them read from stdin
and write to stdout
,
respectively.
size_t mpq_out_str (FILE *stream, int base, mpq_t op) | Function |
Output op on stdio stream stream, as a string of digits in base
base. The base may vary from 2 to 36. Output is in the form
num/den or if the denominator is 1 then just num .
Return the number of bytes written, or if an error occurred, return 0. |
size_t mpq_inp_str (mpq_t rop, FILE *stream, int base) | Function |
Read a string of digits from stream and convert them to a rational in
rop. Any initial white-space characters are read and discarded. Return
the number of characters read (including white space), or 0 if a rational
could not be read.
The input can be a fraction like The base can be between 2 and 36, or can be 0 in which case the leading
characters of the string determine the base, |