The BCX BASIC to C translator
http://www.bcxgurus.com/does this using the BCX vchr function.
The BASIC code
DIM Text$
Text$ = vchr$(66, 97, 99, 107, 32 116 111, 32, 116 101, 120, 116, 33)
PRINT Text$
is converted by BCX to the C code
// *************************************************************
// Created with BCX -- The BASIC To C Translator (ver pc5.08.1103b)
// BCX (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005 by Kevin Diggins
// *************************************************************
// Translated for compiling with a C Compiler
// *************************************************************
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
// *************************************************
// User Global Variables
// *************************************************
static char Text[2048];
// *************************************************
// Standard Prototypes
// *************************************************
char* BCX_TmpStr(size_t);
char* vchr (int,...);
// *************************************************
// Main Program
// *************************************************
int main(int argc, char *argv[])
{
strcpy(Text,vchr(13,66,97,99,107,32,116,111,32,116,101,120,116,33));
printf("%s\n",Text);
return 0; // End of main program
}
// *************************************************
// Runtime Functions
// *************************************************
char *BCX_TmpStr (size_t Bites)
{
static int StrCnt;
static char *StrFunc[2048];
StrCnt=(StrCnt + 1) & 2047;
if(StrFunc[StrCnt]) free (StrFunc[StrCnt]);
return StrFunc[StrCnt]=(char*)calloc(Bites+128,sizeof(char));
}
char *vchr(int charcount, ...)
{
register int c = 0, i = charcount;
char *s_ = BCX_TmpStr(charcount + 1);
va_list marker;
s_
= 0;
va_start(marker, charcount);
while(i-- > 0) s_[c++] = va_arg(marker,int);
va_end(marker);
return s_;
}
The first parameter in the vchr function is the count of the characters to be converted. This makes it possible to embed an ASCII 0 into the string.
Robert Wishlaw