Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1994
*January
*February
*March
*April
*May
*June
*July
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1994

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: C program and Mathematica

  • To: mathgroup at yoda.physics.unc.edu
  • Subject: Re: C program and Mathematica
  • From: tgayley (Todd Gayley)
  • Date: Thu, 10 Feb 1994 11:36:49 -0600

Tom Fister (tfister at cornea.mbvlab.wpafb.af.mil) writes:

>>From Tom Fister
>
>I would like to thank everyone who
>sent me help on the matrix printing 
>problem.  Now, I have another question.
>
>I am trying to install a c program 
>into mathemtica.  The program will
>return an integer list and a string.
>I can get it to return either an
>integer string or list but not both
>I would like to return a list in the form
>  
>    {{1,2,3},"teststring"}
>    
>The C program is as follows
>
>
>int main(argc,argv)
>    int argc;
>    char  *argv[];
>    
>    {
>     return MLMain(argc,argv);
>    }
>
>   
>int   test()
>     {
>     char string[100];
>     int  array[3];
>     
>     strcpy(string,"teststring");
>
>     array[0]=1;
>     array[1]=2;
>     array[2]=3;
>
>     MLPutIntegerList(stdlink,array,3);
>     MLPutSting(stdlink,string);
>     }
>  
>
>  And, I have created a .tm file.  I am
>  compiling using mcc.   


The problem is that your external function does not return a list of two
things; it returns two things. A Mathematica function can only return one
thing. You need to manually wrap your integer list and string in a list.
Thus, your "putting" code should look like:

     MLPutFunction(stdlink, "List", 2);
     MLPutIntegerList(stdlink,array,3);
     MLPutString(stdlink,string);

I presume also that you have used Manual as the :ReturnType: in your .tm file.

--Todd






  • Prev by Date: Mathematica is prospering
  • Next by Date: eps export of graphics on Mma/Windows 3.1
  • Previous by thread: Mathematica is prospering
  • Next by thread: eps export of graphics on Mma/Windows 3.1