MathGroup Archive 2011

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

Search the Archive

Problem with MLGetReal(Double) in Mathlink

  • To: mathgroup at smc.vnet.net
  • Subject: [mg119080] Problem with MLGetReal(Double) in Mathlink
  • From: Soroush Heidari <soroush.heidari at gmail.com>
  • Date: Sat, 21 May 2011 06:48:17 -0400 (EDT)

When I change the simple addtwo program in order to get 2 Real
(Double) numbers and get a Real result, the result is wrong (5+4 =
97986213 !) What is the problem.
Thanks...
***********************************************************************
#include <stdio.h>
#include "mathlink.h"

int main( int argc, char* argv[])

{
	double a, b;
	double ans;

	MLINK lp;
	MLEnvironment env;
	printf( "Enter two integers: a and b\n\t" );
	scanf( "%d %d", &a, &b);
	env = MLInitialize(NULL);
	if(env == NULL) return 1;
	lp = MLOpen(argc, argv);
	if(lp == NULL) return 1;

	MLPutFunction(lp, "Plus", 2);
		MLPutDouble(lp, a);
		MLPutDouble(lp, b);
	MLEndPacket(lp);

	/* skip any packets before the first ReturnPacket */
	while (MLNextPacket(lp) != RETURNPKT) MLNewPacket(lp);

	MLGetDouble(lp, &ans);
	printf( "ans = %d\n", ans);
	MLClose(lp);
	MLDeinitialize(env);
	return 0;
}


  • Prev by Date: Re: NDSolve with NIntegrate for a PDE where the unknown function is integrated wrt its variables
  • Next by Date: Re: binary notebook
  • Previous by thread: Re: MLGetReal(Double) Problem in MathLink
  • Next by thread: Re: Problem with MLGetReal(Double) in Mathlink