NAME

strcoerce - coerce between numeric values and strings

SYNOPSIS

#include <basic/string.h>

short cvi(s)
struct string *s;

float cvs(s)
struct string *s;

double cvd(s)
struct string *s;

struct string mkiS(ia)
short ia;

struct string mksS(fa)
float fa;

struct string mkdS(da)
double da;

DESCRIPTION

These functions allow numeric values to be stored in and retrieved from strings.  This ability is necessary because the string type is the only type of variable that can be stored in a file without translation (within the constraints of the BASIC language).  In these functions, the bytes are moved without interpretation.  Therefore it can not be guaranteed that cvi, cvs and cvd will produce properly formatted numeric values unless these functions are passed strings produced by mkiS, mksS and mkdS, respectively.  Furthermore, the formats of numeric values are machine dependent.  Thus one can not expect that a file of numeric values encoded in this way will be portable to another system. 

Cvi returns a short value corresponding to the first two bytes of the string pointed to by s.  This function implements the BASIC CVI function. 

Cvs returns a float value corresponding to the first four bytes of the string pointed to by s.  This function implements the BASIC CVS function. 

Cvd returns a double value corresponding to the first eight bytes of the string pointed to by s.  This function implements the BASIC CVD function. 

MkiS returns a two byte string corresponding to the short value ia.  This function implements the BASIC MKI$ function. 

MksS returns a four byte string corresponding to the float value fa.  This function implements the BASIC MKS$ function. 

MkdS returns a eight byte string corresponding to the double value da.  This function implements the BASIC MKD$ function. 

SEE ALSO

string(inc)
cvi, cvs, cvd(func), mki$, mks$, mkd$(func)

DIAGNOSTICS

Cvi, cvs and cvd generate error 5 (Illegal function call) if the string pointed to by s is too short, i.e., has length less than two, four and eight, respectively. 

from The Basmark QuickBASIC Programmerís Manual by Lawrence Leinweber