Node:Formatted Input Functions, Next:, Previous:Formatted Input Strings, Up:Formatted Input



Formatted Input Functions

Each of the following functions is similar to the corresponding C library function. The plain scanf forms take a variable argument list. The vscanf forms take an argument pointer, see Variadic Functions, or man 3 va_start.

It should be emphasised that if a format string is invalid, or the arguments don't match what the format specifies, then the behaviour of any of these functions will be unpredictable. GCC format string checking is not available, since it doesn't recognise the GMP extensions.

No overlap is permitted between the fmt string and any of the results produced.

int gmp_scanf (const char *fmt, ...) Function
int gmp_vscanf (const char *fmt, va_list ap) Function
Read from the standard input stdin.

int gmp_fscanf (FILE *fp, const char *fmt, ...) Function
int gmp_vfscanf (FILE *fp, const char *fmt, va_list ap) Function
Read from the stream fp.

int gmp_sscanf (const char *s, const char *fmt, ...) Function
int gmp_vsscanf (const char *s, const char *fmt, va_list ap) Function
Read from a null-terminated string s.

The return value from each of these functions is the same as the standard C99 scanf, namely the number of fields successfully parsed and stored. %n fields and fields read but suppressed by * don't count towards the return value.

If end of file or file error, or end of string, is reached when a match is required, and when no previous non-suppressed fields have matched, then the return value is EOF instead of 0. A match is required for a literal character in the format string or a field other than %n. Whitespace in the format string is only an optional match and won't induce an EOF in this fashion. Leading whitespace read and discarded for a field doesn't count as a match.