This is documentation for Mathematica 6, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)
MathLink C Function


int MLGetString(MLINK link, const char **s)
gets a character string from the MathLink connection specified by link, storing the string in s.
  • MLGetString() allocates memory for the character string. You must call MLReleaseString() to disown this memory. If MLGetString() fails and the function's return value indicates an error, do not call MLReleaseString() on the contents of s.
  • MLGetString() returns immutable data.
  • MLGetString() creates a string that is terminated by \0.
  • MLGetString() stores single \ characters from Mathematica as pairs of characters \\.
  • MLGetString() stores special characters from Mathematica in a private format.
  • MLGetString() returns 0 in the event of an error, and a nonzero value if the function succeeds.
  • Use MLError() to retrieve the error code if MLGetString() fails.
  • MLGetString() is declared in the MathLink header file mathlink.h.
#include "mathlink.h"

/* read a string from a link */

void f(MLINK lp)
    const char *string;

    if(! MLGetString(lp, &string))
            /* unable to read the string from lp */

    /* ... */

    MLReleaseString(lp, string);