117 views
in System Integration by
Hi,

 

I noticed that when I use the next sample code, the last char will not be exchanged

// The variables store some text and the name of a file where the text // should be stored.

var string text = ...;

var string fileName = ...;

$if !$prototyper

 native ( fileName, text )

 {

/* Query the length of the both strings */

int fileNameLen = EwGetStringLength( fileName );

int textLen = EwGetStringLength( text );

/* Reserve memory to accommodate the ANSI version of the strings. Note the additional zero-terminator sign. */

char* bufFileName = malloc( fileNameLen + 1 );

char* bufText = malloc( textLen + 1 );

FILE* file;

/* Convert the strings from 16-bit character format in 8-bit ANSI */

EwStringToAnsi( fileName, bufFileName, fileNameLen, ' ' );    <<< Should this be fileNameLen + 1

EwStringToAnsi( text, bufText, textLen, ' ' );   <<< Should this be textLen + 1

/* Open the file and write in it the given text */

file = fopen( bufFileName, "w" );

fputs( bufText, file );

fclose( file );

/* Finally release the temporarily reserved memory. */

free( bufFileName );

free( bufText );

}

$endif

1 Answer

0 votes
by

Hello Karijn Wessing,

thank you very much for pointing out the documentation error. Of course the correct version should use + 1 according to the documentation of EwStringToAnsi()  function. We will correct this example code.

Best regards

Paul Banach

Embedded Wizard Website | Privacy Policy | Imprint

...