XPRBreadlinecb
XPRBreadlinecb |
Purpose
Synopsis
int XPRBreadlinecb(char *(*fgs)(char *,int,void *), void *file, int length, const char *format, ...);
Arguments
fgs
|
|||||||||||||
file
|
Pointer to a data file.
|
||||||||||||
length
|
Maximum length of any text string to be read.
|
||||||||||||
format
|
String indicating the format of the data line to be read, which may be one of:
The number of format parameters is arbitrary.
|
||||||||||||
...
|
Addresses of items that are to be read, separated by commas.
|
Return value
Number of data items read.
Example
The following opens a data file for reading, reads a line with text and a double value, separated by a semi-colon, and then reads a line with two integers and a string of up to ten characters marked by single quotes, all separated by blanks, before finally closing the file.
double value; FILE *datafile; char name[100]; int i[2]; ... datafile=fopen("filename", "r"); XPRBreadlinecb(XPRB_FGETS, datafile, 99, "T;g", name, &value); XPRBreadlinecb(XPRB_FGETS, datafile, 50, "i i s[10]", &i[0], &i[1], name); fclose(datafile);
Further information
This function reads input data files in a format compatible with the
diskdata command of mp-model and Mosel. Data lines in the input file may be continued over several lines by using the line continuation sign
&. The input file may also contain comments (preceded by
!) and empty lines, both of which are skipped over. The data file is accessed with standard C functions (
fopen,
fclose). The format string gives the type of data item to be read. Each string type may (optionally) be followed by the maximum length to be read. Otherwise, the maximum length is assumed to be
length. The type of separator signs (
e.g.
,
;
:) used in the data file needs to be indicated between each pair of format options. As with the C functions
printf or
scanf, the format string is followed by the addresses where the data are stored. With function
XPRBsetdecsign the decimal sign used in the data input may be changed, for instance to use a decimal comma.
Related topics