int QSget_solution (QSprob p, double *value, double *x, double *pi,
    double *slack, double *rc)
/* p is an initialized QSprob, a handle to an existing LP problem  */
/* Assume that p was solved with QSopt_dual() or QSopt_primal, and */
/* that the status code indicates that an optimal solution was     */
/* obtained.  We will grab and print all solution components.      */

int rval, ncols, nrows, i, j;
double value;
double *x, *pi, *slack, *rc;
char **colnames, **rownames;

ncols = QSget_colcount (p);
nrows = QSget_rowcount (p);

/* Get the variable names and the constraint names, for printing */

colnames = (char **) malloc (ncols * sizeof (char *));
rownames = (char **) malloc (nrows * sizeof (char *));
rval = QSget_colnames (p, colnames);
if (rval) {
    fprintf (stderr, 
             "Could not get column names, error code %d\n", rval);
    /* free the memory for colnames and rownames                 */
    /* return an error code                                      */
}
rval = QSget_rownames (p, rownames);
if (rval) {
    fprintf (stderr, 
             "Could not get row names, error code %d\n", rval);
    /* free the memory for colnames and rownames                 */
    /* return an error code                                      */
}

/* Allocate memory for the solution components.                  */

x  = (double *) malloc (ncols * sizeof (double));
rc = (double *) malloc (ncols * sizeof (double));
pi = (double *) malloc (nrows * sizeof (double));
slack = (double *) malloc (nrows * sizeof (double));

rval = QSget_solution (p, &value, x, pi, slack, rc);
if (rval) {
    fprintf (stderr, 
             "Could not get solution, error code %d\n", rval);
    /* free the memory for x, rc, pi, slack, colnames, rownames  */
    /* return an error code                                      */
}

printf ("Objective Value = %.6f\n", value);
for (j = 0; j < ncols; j++) {
    printf ("%s = %.6f, reduced cost = %.6f\n", 
            colnames[j], x[j], rc[j]);
}
for (i = 0; i < nrows; i++) {
    printf ("dual %s = %.6f, slack = %.6f\n", 
            rownames[i], pi[i], slack[i]);
}

/* Free the memory, including the individual names of cols and rows */

free (x);  free (rc);  free (pi);  free (slack);
for (j = 0; j < ncols; j++) {
    /* Use QSfree for memory from QSopt functs  */
    QSfree (colnames[j]);
}
free (colnames);
for (i = 0; i < nrows; i++) {
    /* Use QSfree for memory from QSopt functs  */
    QSfree (rownames[i]);   
}
free (rownames);