WSGetNumberAsString (C Function)

int WSGetNumberAsString(WSLINK l, const char **s)

reads the next number on the WSTP connection specified by l as a string of ASCII characters representing the number value stored in the string s.

Details

  • WSGetNumberAsString() allocates memory to store the string value. To release the memory allocated by WSGetNumberAsString(), call WSReleaseString() on the contents of s. If WSGetNumberAsString() fails, do not call WSReleaseString() on the contents of s.
  • WSGetNumberAsString() returns 0 on error and a nonzero value on success.
  • WSGetNumberAsString() is declared in the WSTP header file wstp.h.

Examples

Basic Examples  (1)

#include "wstp.h"

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

void f(WSLINK l)
{
    switch(WSGetType(l))
    {
        case WSTKINT:
        {
            int rawType;
            rawType = WSGetRawType(l);
            if(rawType == WSTK_WSSHORT)
            {
                short theNumber;
                WSGetInteger16(l, &theNumber);
                /* ... */
            }
            else if(rawType == WSTK_WSINT)
            {
                int theNumber;
                WSGetInteger32(l, &theNumber);
                /* ... */
            }
            else
            {
                const char *theNumber;
                WSGetNumberAsString(l, &theNumber);
                /* ... */
                WSReleaseString(l, theNumber);
            }
        }
        break;
        case WSTKREAL:
            /* ... */
    }
}