WSBytesToGet()
This feature is not supported on the Wolfram Cloud.

int WSBytesToGet(WSLINK link,int *n)
calculates the number of bytes left to read in the textual representation of the current data and stores the result in n.

DetailsDetails

  • WSTP has the ability to convert the current readable data on the link to types other than its link representation on the fly. WSBytesToGet() converts the current data to a character string representation.
  • WSBytesToGet() returns 0 in the event of an error and a nonzero value if the function succeeds.
  • Use WSError() to retrieve the error code if WSBytesToGet() fails.
  • WSBytesToGet() is declared in the WSTP header file wstp.h.

ExamplesExamplesopen allclose all

Basic Examples  (1)Basic Examples  (1)

#include <stdlib.h>
#include <string.h>
#include "wstp.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(WSGetType(lp))
    {
        case MLTKSTR:
            if(! WSBytesToGet(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(! WSGetString(lp, &mlstring))
                { /* unable to get the string from lp */ }

            memcpy(string, mlstring, incoming_bytes);

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

            break;
        /* ... */
    };

    /* ... */
}