MLBytesToGet (C 函数)

MLBytesToGet 已经被 WSBytesToGet 所取代.

int MLBytesToGet(MLINK link,int *n)

计算当前数据的文本表示中剩余的要读取的字节数,并把结果存在 n 中.

更多信息

  • MathLink 具有实时转换链接中的当前可读数据为不同于链接的其他类型的能力. MLBytesToGet() 把当前数据转换为字符字符串表示.
  • MLBytesToGet() 如果为错误事件返回0,如果函数成功则返回非零值.
  • 如果 MLBytesToGet()失败,使用 MLError() 检索错误代码.
  • MLBytesToGet() 在 MathLink 的标头文件 mathlink.h 中被声明.

范例

基本范例  (1)

#include <stdlib.h>
#include <string.h>
#include "mathlink.h"

/* check the incoming string size to allocate enough memory to store the string */

void f(MLINK lp)
{
    int incoming_bytes;
    char *string;
    const char *mlstring;

    switch(MLGetType(lp))
    {
        case MLTKSTR:
            if(! MLBytesToGet(lp, &incoming_bytes))
                { /* unable to get the size of the string */ }

            string = (char *)malloc(incoming_bytes + 1);
            if(string == (char *)0)
                { /* memory allocation failed */ }

            if(! MLGetString(lp, &mlstring))
                { /* unable to get the string from lp */ }

            memcpy(string, mlstring, incoming_bytes);

            *(string + incoming_bytes) = '\0';

            break;
        /* ... */
    };

    /* ... */
}