Next: , Previous: Multiset functions, Up: Multisets


11.6 Reading and writing multisets

The library provides functions for reading and writing multisets to a file as binary data or formatted text.

— Function: int gsl_multiset_fwrite (FILE * stream, const gsl_multiset * c)

This function writes the elements of the multiset c to the stream stream in binary format. The function returns GSL_EFAILED if there was a problem writing to the file. Since the data is written in the native binary format it may not be portable between different architectures.

— Function: int gsl_multiset_fread (FILE * stream, gsl_multiset * c)

This function reads elements from the open stream stream into the multiset c in binary format. The multiset c must be preallocated with correct values of n and k since the function uses the size of c to determine how many bytes to read. The function returns GSL_EFAILED if there was a problem reading from the file. The data is assumed to have been written in the native binary format on the same architecture.

— Function: int gsl_multiset_fprintf (FILE * stream, const gsl_multiset * c, const char * format)

This function writes the elements of the multiset c line-by-line to the stream stream using the format specifier format, which should be suitable for a type of size_t. In ISO C99 the type modifier z represents size_t, so "%zu\n" is a suitable format.1 The function returns GSL_EFAILED if there was a problem writing to the file.

— Function: int gsl_multiset_fscanf (FILE * stream, gsl_multiset * c)

This function reads formatted data from the stream stream into the multiset c. The multiset c must be preallocated with correct values of n and k since the function uses the size of c to determine how many numbers to read. The function returns GSL_EFAILED if there was a problem reading from the file.


Footnotes

[1] In versions of the GNU C library prior to the ISO C99 standard, the type modifier Z was used instead.