2
$\begingroup$

I'm using "mathlink.h" to call Mathematica from a C program. I send a computation to Mathematica and its return result is a very big number (100 digits). Hence, I want to read that number as a string.

How can I do it using MathLink?

Thanks,

$\endgroup$
2
$\begingroup$

You could simply wrap your computation in

MLPutFunction(link, "ToString", 1);

and convert your result to a string. After that you can use MLGetString.

$\endgroup$
  • $\begingroup$ One problem is if the output is an expression, say $x^2 + x + 1$, then the ToString method will return in un-readable format. What should I do if I want to read arbitrary output as a string? Like for the expression above, I expect to get output as exactly $x^2 + x + 1$. $\endgroup$ – Loi.Luu Oct 21 '13 at 6:37
  • $\begingroup$ and I see there is no other option for ToString method. $\endgroup$ – Loi.Luu Oct 21 '13 at 6:37
  • 1
    $\begingroup$ @Loi.Luu You question was how you can send very big numbers as string through MathLink. Why do you now want to send expressions? Addtionally, ToString[x^2 + x + 1, InputForm] gives a string of valid Mathematica syntax. $\endgroup$ – halirutan Oct 21 '13 at 7:36
  • $\begingroup$ Sorry to make you confused, I thought I can apply the same technique to expression. You are correct in both answers, thank you for your help :) $\endgroup$ – Loi.Luu Oct 21 '13 at 7:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.