MathGroup Archive 2011

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

Search the Archive

MLGetReal(Double) Problem in MathLink

  • To: mathgroup at smc.vnet.net
  • Subject: [mg119064] MLGetReal(Double) Problem in MathLink
  • From: Soroush Heidari Pahlavian <shp_maya at yahoo.com>
  • Date: Sat, 21 May 2011 06:45:21 -0400 (EDT)

When I change the simple addtwo program in order to work with Real(Double)
numbers instead of Integer ones, the answer goes wrong (4+5 = -143566321 !).
What is the problem with the following code?
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 doubles: 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: Maximize a single variable and solve for the rest
  • Next by Date: Re: Question about DurbinWatsonD
  • Previous by thread: Re: how do I plot many points?
  • Next by thread: Re: MLGetReal(Double) Problem in MathLink