MathGroup Archive 2008

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

Search the Archive

Re: a mathlink question


Hi,

something like:

#include "mathlink.h"

static int prev=0;

void add_to_previous_sum(int x) {
   prev+=x;
   return prev;
  }

:Begin:
:Function: add_to_previous_sum
:Pattern: AddToPreviousSum[x_Interger]
:Arguments: {x}
:ArgumentType: {Integer}
:ReturnType: Integer
:End:

int main(int argc, char *argv[]) {
   return MLMain(argc,argv);
}

Regards
   Jens

GS wrote:
> I would like to call a C-program from Mathematica. All the examples in
> the MathLink tutorials (like AddTwo[i,j]) work like this: they are
> called from Mathematica, are executed, send the result to Mathematica
> and exit.
> 
> I would like a C-program to not exit after the execution, and keep the
> memory of the previous inputs. Say, I want an external C-program, to
> be called as AddToPreviousSum[x]. When it is first called, it returns
> x. When it is called the second time AddToPreviousSum[y], it returns x
> +y. When it is called the third time AddToPreviousSum[z], it returns x
> +y+z, and so on.
> 
> How do I implement this in C using MathLink?
> 
> Thanks.
> GS.
> 


  • Prev by Date: minor progress with 6.0 Documentation
  • Next by Date: Re: Gradient fill as Background for Plot
  • Previous by thread: Re: a mathlink question
  • Next by thread: Re: a mathlink question