Page 1 of 1

help on sprintf

Posted: Sat Jun 02, 2007 8:54 pm
by frederic
Hello, i've an error with this code and i don't understand why.
With 1 arg, it's working, and with 2 args no :(
Any idea ?

Code: Select all

;===============================
; WORKING
text$  = ""

format$ = "nombre : %d"

sprintf_( text$, format$, 5)

Debug text$
;===============================
; NOT WORKING
format$ = "nombre : %d, nombre 2 : %d"

sprintf_( text$, format$, 5, 6)

Debug text$
;===============================

Posted: Sat Jun 02, 2007 9:32 pm
by Nik
I don't think the PureBasic Compiler has support for var_args, so that might not work, however I guess you could use Inline ASM to work around this,

Posted: Sat Jun 02, 2007 10:56 pm
by Fred
yes, variable arguments aren't supported in PB. RThe easiest workaround is to use the vsnprintf_() function which takes an array in parameter. But why do you need such a function in PureBasic, while you have many build-in string fonctions ?

Posted: Sat Jun 02, 2007 11:00 pm
by michaeled314
Or you can call a function from a library

Posted: Sun Jun 03, 2007 12:05 pm
by frederic
ok thanks for the precision about pbcompiler.

Why i need this function ? Just to try :) Lot of codes are for win32 api, so i'm doing some research with linux functions because i'm not on windows.