QSopt QSget_colnames QSopt > Callable Library > Function List
  QSopt
  Downloads
  LP Info
  Software
  Problem Formats
  Callable Library
  Overview
Function List
  Rational Solver
  Beta
  Contact Info
Purpose
Copy the names of the columns in the problem.
Synopsis
int QSget_colnames (QSprob p, char **colnames)
Arguments
p a handle to an initialized problem.
colnames returns an array of strings specifying the names of the columns (variables); this field should point to an array of length at least ncols, the number of columns in the problem.
Returns
A zero value if the function terminated correctly, and a non-zero value if an error occurred.
Description

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.

Example
/* 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);  
 
QSopt | Problem Formats | Downloads Back
Last Updated: November 2003