MathGroup Archive 1999

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

Search the Archive

Re: MathLink & strings

  • To: mathgroup at smc.vnet.net
  • Subject: [mg21173] Re: MathLink & strings
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Fri, 17 Dec 1999 01:22:56 -0500 (EST)
  • Organization: Universitaet Leipzig
  • References: <831vhq$g7c@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Roger,

you have just to read the documetation. Mathematica uses Unicode strings
(16 byte) and not ordinary char types. For plane ASCII characters you
can
send the strings with MLPutString(). If you declare a MathLink function
with
a string argument the C-function must declare it as 

const char *someMathString

and not

char *someMathString

Except the '\\' all characters can be done as usual.
You may look into the MLPutString(), MLPutByteString() and
MLPutUnicodeString() functions
in your documentation. You may also use MLNextCharacter() to convert
from Unicode strings
like

   MLGetString(stdlink,(const char **) &unistr);
   len=strlen(unistr);
   endstr=unistr+len;
   imagedata=pbm=(char *)calloc(len,sizeof(char));
   for(j=i=0,sp=unistr; i<len; i++) {
     pbm[j++]= (char) MLNextCharacter((const char **)&sp,(const char
*)endstr);
     if(!pbm) break;
    }
   MLDisownString(stdlink,unistr);

How ever as long as you dont't tell what you plan to do I can't help you
more.

BTW: I have never had problems with the MathLink documentation.
Hopefully WRI will have more success than Microsoft - it will be
a better world.

Regards
  Jens

Roger Mason wrote:
> 
> Hi,
> 
> I am trying to send strings from Mathematica to C via MathLink. I have
> been trying now for two days to accomplish this seemingly simple task.
> Much of the problem stems from the absolutely hopeless documentation for
> MathLink functions. If Mathematica were free, one might sigh and accept
> the kindness of others in making code available. However, Mathematica is
> (very decidedly) not free. Is WRI going to turn into another monster
> like Micro$oft?
> 
> So much for venting spleen.
> 
> Does anyone have any examples of C code that implements string transfer
> between Mathematica and C, in both directions? If you do, please make
> clear what the types of the variables must be (this is an area where I
> came to grief by assuming that the documentation is accurate!).
> 
> Many thanks in advance.
> 
> Roger Mason


  • Prev by Date: Re: MathLink & strings
  • Next by Date: Re: Re: Running Mathematica under Linux Red Hat
  • Previous by thread: Re: MathLink & strings
  • Next by thread: Re: Exact value of Cos[Pi/17]