OpenersNotesSection(Spacer1)Details

WSTP provides functions such as (NonWLLink[WSPutString(), paclet:ref/c/WSPutString]), (NonWLLink[WSPutSymbol(), paclet:ref/c/WSPutSymbol]), (NonWLLink[WSPutInteger32(), paclet:ref/c/WSPutInteger32]), and (NonWLLink[WSPutReal64(), paclet:ref/c/WSPutReal64]) for sending strings, symbols, integers, and floating-point numbers. However, it is sometimes convenient to send these types using a character string representation. WSBytesToPut() works with (NonWLLink[WSPutType(), paclet:ref/c/WSPutType]), (NonWLLink[WSPutRawSize(), paclet:ref/c/WSPutRawSize]) and (NonWLLink[WSPutRawData(), paclet:ref/c/WSPutRawData]) to send a type using a character string representation.

WSBytesToPut() 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 WSBytesToPut() fails.

WSBytesToPut() 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 <string.h>
#include "wstp.h"

/* send an approximation of Pi across a link */

void f(WSLINK lp)
{
	char *Pi = "3.141592654";
	int bytes_left, i;

	if(! WSPutType(lp, WSTKOLDREAL))
		{ /* unable to send the data type to lp */ }

	if(! WSPutRawSize(lp, strlen(Pi))
		{ /* unable to send the length of Pi to lp */ }

	if(! WSBytesToPut(lp, &bytes_left))
		{ /* unable to get the remaining bytes to send from lp */ }

	i = 0;
	while(bytes_left > 0)
	{
		/* send the data one byte at a time */
		if(! WSPutRawData(lp, Pi + i, 1))
			{ /* unable to send a character of Pi to lp */ }

		if(! WSBytesToPut(lp, &bytes_left))
			{ /* unable to get the remaining bytes to send from lp */ }

		i++;
	}
}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(NonWLLink[WSPutType(), paclet:ref/c/WSPutType])}})}})

({{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])}})}})