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

MLPutString()

int MLPutString(MLINK link, const char*s)
puts a null-terminated string of C characters to the MathLink connection specified by link.
  • A raw backslash in the string must be sent as two characters '\\'.
  • Special characters can be sent only using the format returned by MLGetString().
  • MLPutString() returns 0 in the event of an error, and a nonzero value if the function succeeds.
  • Use MLError() to retrieve the error code if MLPutString() fails.
  • MLPutString() is declared in the MathLink header file mathlink.h.
#include "mathlink.h"

/* send a string representing an expression to a Mathematica kernel
for evaluation */

void f(MLINK lp)
{
/* construct the packet to be sent to the kernel */
    MLPutFunction(lp, "EvaluatePacket", 1);
MLPutFunction(lp, "ToExpression", 1));
MLPutString(lp, (const char *)"3+4/Sqrt[19.2]"));
MLEndPacket(lp));

/* send the packet */
    if(! MLFlush(lp))
        { /* unable to flush an outgoing data buffered in lp */ }

}