Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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,

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You could simply wrap your computation in

MLPutFunction(link, "ToString", 1);

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

share|improve this answer
    
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
1  
@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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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