This HTML automatically generated with rman for NEMO
Table of Contents

Name

mstr_init, mstr_open, mstr_close, mstr_count, mstr_multi - multiple template based file-stream utilities

Synopsis


#include <stdinc.h>mstr *mstr_init(string template)stream mstr_open(mstr *mp,
string mode)void mstr_close(mstr *mp)int mstr_count(mstr *mp)int mstr_multi(mstr
*mp)
Descriptionmstr_init() returns a structure that is used to aid in writing
to a set of related files whose name is derived from a template and embedded
integer counter. The argument is a string which can optionally contain a
template in the form of a  printf(3) style string in which an integer is
used to derive a variable name, e.g. run%03d.dat. This call will also open
the first (or only, if no template is used)  file for writing. mstr_open
will however have  to be used to get a stream in order to write actual
data (see example below). mstr_open() returns the stream (see stropen(3NEMO))
to the next file.  It also closes the previously opened stream, if there
was such one. 
mstr_close() closes access to an mstr and free’s all allocated
memory associated with it. 
mstr_count() returns the number of previous calls
to mstr_open. 
mstr_multi() returns if multiple files will be used in mstr_open
(currently set by checking for the existence of the % character in the
filename. 
Example
    mstr *mp = mstr_init("test%03d.dat");
    for (int i=0; i<10; i++) {
       stream ostr = mstr_open(mp,"w");
       fprintf(ostr,"Hello world, i=%d\n",i);
    }
    mstr_close(mp);

Todo

Add reading them back in again

See Also

stropen(3NEMO)

Author

Peter Teuben

Files


~/src/kernel/io      mstropen.c

Update History


8-may-2002    created, on Amtrak    Peter
14-sep-2002    added mstr_count,mode    Peter


Table of Contents