# Read return value as string by Mathlink.h

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,

-
add comment

## 1 Answer

You could simply wrap your computation in

MLPutFunction(link, "ToString", 1);


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

-
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$. –  Loi.Luu Oct 21 '13 at 6:37
and I see there is no other option for ToString method. –  Loi.Luu Oct 21 '13 at 6:37
@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. –  halirutan Oct 21 '13 at 7:36
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 :) –  Loi.Luu Oct 21 '13 at 7:48
add comment