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; }