 |
A QSprob data structure always contains names for each column of the LP problem; if the application does not give explicit column names, then the QSopt library will generate them when the problem is loaded and as new columns are added. The QSget_colnames function will allocate memory for each of the strings that are returned via the array of pointers in colnames ; when the application no longer needs the names, the memory associated with each of the strings should be freed; since the memory for the strings was allocated by the QSopt library, the memory must be freed with calls to QSfree rather than by the system free() function.
|
 |
/* p is an initialized QSprob, a handle to an existing LP problem */
int rval, ncols, j;
char **colnames;
ncols = QSget_colcount (p);
colnames = (char **) malloc (ncols * sizeof (char *));
rval = QSget_colnames (p, colnames);
if (rval) {
fprintf (stderr,
"Could not get column names, error code %d\n", rval);
} else {
printf ("Variable Names\n");
for (j = 0; j < ncols; j++) {
printf ("%s\n", colnames[j]);
}
/* Need to free the individual names */
for (j = 0; j < ncols; j++) {
/* Use QSfree for mem allocated by QSopt */
QSfree (colnames[j]);
}
}
/* Use free for mem allocated by system malloc */
free (colnames);
|