MLGetNumberAsUTF8String (C 函数)

MLGetNumberAsUTF8String 已经被 WSGetNumberAsUTF8String 所取代.

int MLGetNumberAsUTF8String(MLINK l, const unsigned char **s, int *v, int *c)

reads the next number of the MathLink connection specified by l as a string of UTF-8 characters representing the number value stored in the string s of length v with c characters.

更多信息

  • MLGetNumberAsUTF8String() allocates memory to store the string value. To release the memory allocated by MLGetNumberAsUTF8String(), call MLReleaseUTF8String() on the contents of s. If MLGetNumberAsUTF8String() fails, do not call MLReleaseUTF8String() on the contents of s.
  • MLGetNumberAsUTF8String() returns 0 on error and a nonzero value if the function succeeds.
  • MLGetNumberAsUTF8String() is declared in the MathLink header file mathlink.h.

范例

基本范例  (1)

#include "mathlink.h"

/* A function for reading an integer from a link */

void f(MLINK l)
{
    switch(MLGetType(l))
    {
        case MLTKINT:
        {
            int rawType;
            rawType = MLGetRawType(l);
            if(rawType == MLTK_MLSHORT)
            {
                short theNumber;
                MLGetInteger16(l, &theNumber);
                /* ... */
            }
            else if(rawType == MLTK_MLINT)
            {
                int theNumber;
                MLGetInteger32(l, &theNumber);
                /* ... */
            }
            else
            {
                const unsigned char *theNumber;
                int length, characters;
                MLGetNumberAsUTF8String(l, &theNumber, &length, &characters);
                /* ... */
                MLReleaseUTF8String(l, theNumber, length);
            }
        }
        break;
        case MLTKREAL:
            /* ... */
    }
}