OpenersNotesSection(Spacer1)Details

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 (NonWLLink[WSError(), paclet:ref/c/WSError]) to retrieve the error code if WSBytesToGet() fails.

WSBytesToGet() is declared in the WSTP header file (RefLink[wstp.h, paclet:ref/file/wstp.h]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (1)

OpenersExampleSection0(Spacer1)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(WSLINK lp)
{
	int incoming_bytes;
	char *string;
	const char *wsstring;

	switch(WSGetType(lp))
	{
		case WSTKSTR:
			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, &wsstring))
				{ /* unable to get the string from lp */ }

			memcpy(string, wsstring, incoming_bytes);

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

			break;
		/* ... */
	};

	/* ... */
}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(NonWLLink[WSGetNext(), paclet:ref/c/WSGetNext])  ▪  (NonWLLink[WSGetType(), paclet:ref/c/WSGetType])  ▪  (NonWLLink[WSGetData(), paclet:ref/c/WSGetData])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[WSTP C API Developer Guide (Mac OS X), paclet:tutorial/WSTPDeveloperGuide-MacintoshOverview])}, {▪(RefLinkPlain[WSTP C API Developer Guide (Unix and Linux), paclet:tutorial/WSTPDeveloperGuide-UnixOverview])}, {▪(RefLinkPlain[WSTP C API Developer Guide (Windows), paclet:tutorial/WSTPDeveloperGuide-WindowsOverview])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Alphabetical Listing of WSTP C Functions, paclet:guide/AlphabeticalListingOfWSTPCFunctions])}, {▪(RefLinkPlain[Low-Level WSTP Operations, paclet:guide/LowLevelWSTPOperations])}})}})